A curated list of terminal commands for Ubuntu/Linux.
-
Kill a process
-
Using process name
sudo pkill -9 <process_name>
-
Using process ID
ps aux | grep <process_name>
// Get process IDsudo pkill -9 <PID>
// Kill process using ID -
Using parent process (When sometimes killing the process using PID leaves it defunct)
ps -o ppid=<PID>
// Get parent PIDsudo pkill -9 <PPID>
// Kill process using ID -
Sometimes, Ctrl + Z is used to kill programs when Ctrl + C fails. However, Ctrl + Z does NOT kill the program but merely sends it to the background of the current terminal. To kill such processes and any other process running in a particular window of the terminal.
sudo kill
jobs -p``
-
- Several occasions of compiling a code leaves behind a lot of terminal outputs - errors, warnings and other information. If you’re fed up of scrolling through the terminal to notice each of them, use piping and redirection operators to send the output to files.
- Example
./executable > ~/tmp/output_stored.txt
-
Use these commands to discover different hardwares
lshw
// hardwarelspci
// PCI deviceslsusb
// USB buses,lsblk
// blocked devices andlsmod
// hardware modules plugged into the system
-
Add files to commit
git add .
// Select all files to commitgit add <file_name>
// Select Particular file to commitgit add --all
// Select Deletions to commit -
Commit files
git commit -m <"commit message">
-
Manage files between local and remote repository
-
Get updates from remote repository to local git (Only stored changes, NOT merged into local files)
git fetch <branch_name>
// Branch specific changes to see from remotegit fetch
// All remote changes from all branches -
Push all changes locally committed changes to remote repository
git push origin <branch name>
-
Before pushing to remote, pull to local repository (A pull is basically a fetch + merge )
git pull origin <branch_name>
-
Merge changes from a remote/local branch to local branch
git merge <branch_name>
// If conflicts come up, resolve manually in local files and commit to remote
-
-
Branch Commands
git checkout <branch_name>
// Switch to the specified branchgit checkout <commit_id>
// Switch to a particular commit ID on the current branchgit checkout -b <new_branch_name> <base_branch_name>
-
Discard/Archive edits
git stash
// Remove all new unwanted editsgit stash list
// Obtain the list of stashed or archived changesgit stash save "<message_to_save_edit>"
git stash apply
// Apply last stashed set of changes to editsgit stash apply --index
// Apply particular stashed changes from the list
-
General Commands
git init .
// Initialize git in a local foldergit clone remote_git_url
// Clone a remote repository to a local locationgit status
// Check status of repository to see tracked/committed/uncogit diff
// Check the difference and edits in new uncommitted filesgit branch
// Check the branches availablegit tag
// Check the tags availablegit reset --hard
// Reset the all changes and get to master branchgit log
// See history for commits, messages and authorsgit blame <file_name>
// List the changes, date and authors for the file
-
Configure user credentials
-
Add username for remote git service account
git config --global user.name "<github/bitbucket user_name>"
-
Add email ID for remote git service account
git config --global user.email "<github/bitbucket user_mail_id>"
-
Connect a local repository to remote git service URL
git remote add origin "<github/bitbucket repository URL>"
-
Set the origin/remote git service URL to current local repository
git set-url remote origin "<github/bitbucket repository URL>"
-
- Terminal content handling
clear
// Scroll the terminal to clear view - This does NOT erase the terminal historyreset
// Erase the terminal history and present a clear screentree
// Show the hierachy of existing files in the current folderlocate <file_name>
// Search the folder location of a filepwd
// Print the current working directoryhistory
// Get the history of all terminal commands in the windowman <terminal_command>
// Get the description of the terminal commandtouch <file_name>
// Create
-
Handling Files & Directories
mkdir -p <path_to_file/file_name>
// Create a folder in a specific locationmv <file_to_move> <destination>
// Move a file to a new locationrm <path_to_directory/file_to_remove>
// Delete the particular folder/filerm -rf <path_to_directory_to_remove>
// Delete with -r flag for recursive and -f for forced (-rf Combined both)cp <file_1> <file_2>
// Copy file1 to file2cp -r <directory1> <directory2>
// Copy directory1 to directory2 and create the latter if it doesn't exist
-
Modifying/Viewing files
cat > file_name
// Creates a new file in the particular locationcat file_name
// Displays the content of the file in the terminalcat file_1 file_2 > file_3
// Joins two files (file_1, file_2) and stores the output in a new file file_3more file_name
// Display all the contents of the fileless file_name
// Displays the contents of the file with more [options] (https://en.wikipedia.org/wiki/Less_(Unix))head file_name
// Display the first 10 lines of the filetail file_name
// Display the last 10 lines of the filetail -f file_name
// Display the last 10 lines of a continuously growing in size file
-
Viewing the directory contents
ls
// List files and directories in the current working directoryls -a
// List files including the hidden filesls -R
// List all the files in the sub directoriesls -al
// List files with all permissions, size, owner, date of modification etc.
ifconfig
// Show network information like IP address, HW address and other parametersiwconfig
// Show wireless informationiwlist scan
// Scan for all wireless networks / Run withsudo
, ideallysudo /etc/init.d/networking restart
// Restart the network configuration - All wireless and wired connections
start | stop <service>
// Start or Stop the particular system servicestatus <service>
// Check the status of the running service, whether active or notetc/init.d/service start | stop | retsart
// Toggle a system servicerunlevel
// Get current run level
tar cf <file.tar> < files names| folder>
// Compress the list of files or the folder into a tar named file.tartar xf <file.tar>
// Extracting the content from file.tartar czf <file.tar.gz> <files>
// Create a tar with Gzip compressiontar xzf <file.tar.gz>
// Extract a tar using Gziptar cjf <file.tar.bz2>
// Create a tar with Bzip2 compressiontar xjf <file.tar.bz2>
// Extract a tar using Bzip2gzip <file>
// Compresses file and renames it to file.gzgzip -d <file.gz>
// Decompresses file.gz back to file
date
// Display the date on the terminalcal
// Display the month's calendar on the terminaluptime
// Show the current uptime for the machinew
// Display who is onlinewhoami
// Show the username logged in as, in the current Linux sessionuname -a
// Show the kernel informationdf
// Show the current disk usagedu
// Show the current directtory space usagefree
// Show the swap and memory usagewhereis <application>
// Search for the possible locations of the applicationwhich <application>
// Show the application which will run by default for the applicationhostname
// Displays the current session hostnamehostname -I
// Displays the IP address in the network
chfn
// Change real user name and informationchgrp
// Change group ownership for filechkconfig
// Modify execution of runlevel serviceschmod <options> <permissions> <file_name>
// Change access permission for a file(s)chown
// Change the owner or group for a filechroot
// Run a command with root credentialschsh
// Toggle between login shellcksum
// Perform a CRC checksum for files