Currently migrating my blog from wordpress and other scattered sources.
I periodically update this list with useful bash commands I routinely use. Here, I have used ubuntu based commands for its popularity, although most of them are transfereable to other distros like Manjaro [which I use] by changing package manager from apt to pacman. That being said, I tend to favour installing robby russell’s ohmyzsh to make life easier.
Terminal Commands
- Check the number of processors:
nproc - Check free RAM :
free -hTo continuously monitorwatch free -h - Checking ubuntu version on the system:
lsb_release -a - Checking the processes running as a tree diagram:
pstree - Check resource utilization (like task manager in windows):
toporhtoporytop(not available on all platforms) - Checking sytem file size:
df -ah - Checking file size in directory:
du -sh * - Disk partition and disk usage:
lsblk - Printing output of a command into a log file:
nohup. For eg:nohup lsblkwill output the result oflsblkinto a log file in the current folder.nohup python -u script.py > file.log 2>&1=> Output and error to samefile.lognohup myprogram > myprogram.out 2> myprogram.err=> redirect standard output and standard error to different files
- Opening the current folder (GUI) from terminal:
nautilus . - Checking linux (kernel) verison:
uname -a - Show cpu and motherboard details:
lshw -class cpu - To check who are all logged into the system:
whoorw pushdandpopdto navigate to and back to the directory eg:pushd ~/Desktop- file to print the type of file eg:
file fooprints out file format asfoo:JPEGimage data - search for a file:
locate filename.shprints file location offilename.sh - To constantly update a command every few seconds:
watch tailandheadfor printing the end and beginning of a file.- Functions which give information about a command:
man(manual page),whatis(one line description),info(only available for some commands) - To run a program in the background eg:
firefox & - To capture what is being printed during boot:
journalctl - Checking internet connection eg:
ping 8.8.8.8or mtr 8.8.8.8 - Changing directory/file permissions:
sudo chmod 700 - Changing ownership:
sudo chown - Changing group:
sudo chgrp - Listing the directory structure with depth=2 levels :
tree -d -L 2 printenvwill print out any environment variables you have set.
Running jobs from terminal in background [foreground and pausing]
To run jobs (one or more programs) in foreground and background from terminal. Here, I use firefox as an example to demonstrate the same.
Running programs from terminal
You can always run a job in foreground by typing a command on to the terminal as
firefox

But once the program starts we lose the bash prompt. Another way to start firefox is to run the program in background. This will return bash prompt as shown below.
firefox &

Pause and resume jobs from terminal
Sometimes you need to pause a job that’s running and return to bash prompt and execute some commands and afterwards resume the original job. Press CTRL+Z to pause the original job and return to command prompt as shown below. This will immediately pause firefox and you will note able to use it for browsing the web.

Case 1:
To resume firefox in background run
bg %1

This will resume firefox but in background and returns bash prompt as shown above.
Case 2:
To resume firefox in foreground run
fg %1
This will resume firefox but in foreground, but will not return bash prompt as shown above.
Listing jobs in background and killing them
To list all the jobs running in background run
jobs -l

To kill a job running in background, find job ID (21689) from earlier listing
kill 21689

