Linux is a group of open-sourced operating systems. About 90% of public clouds operate using Linux and about 70% of all smartphones are based on Linux. This makes Linux essential to learn if you plan or currently work in cloud infrastructure, supercomputers, smartphone development, or another area that relies on Linux. The following Linux command cheat sheet may prove useful when refreshing your memory on certain commands.
We have listed all the commands that you might find useful, sorted in alphabetical order.
adduser/addgroup Command
The adduser and addgroup commands add a user and group to the system based on the default configuration indicated in the /etc/adduser.conf file.
$ sudo adduser cloudinstitute
agetty Command
agetty is a program that manages physical and virtual terminals and is summoned by init. When it detects a connection, it opens a tty port, asks for a user’s login name and calls up the /bin/login command. Agetty is a substitute of Linux getty:
$ agetty -L 9600 ttyS1 vt100
alias Command
alias is a helpful shell built-in command for generating aliases (shortcut) to a Linux command on a system. It is useful for creating new and custom commands from existing Shell/Linux commands (which includes options):
$ alias home='cd /home/cloudinstitute/public_html'
The above command will create an alias called home for /home/cloudinstitute/public_html directory so that whenever you type home in the terminal prompt, it will put you in the /home/cloudinstitute/public_html directory.
anacron Command
anacron is a Linux facility that runs commands periodically for days, weeks and months.
It assumes that a system will not run forever, so if a scheduled job is due when the system is off, it’ll run when the machine is turned on.
apropos Command
apropos command searches for and displays a short main page description of a command/program, as follows.
$ apropos adduser
aptitude Command
aptitude is a great text-based interface to the Debian GNU/Linux package management system. Like apt-get and apt, it can install, remove or upgrade software packages on a system.
$ sudo aptitude update
arch Command
arch is a basic command for showing machine architecture or hardware name (similar to uname -m):
$ arch
at Command
at command schedules tasks to run in a future time. It can be used instead of cron and anacron, yet it runs a task once at a given future time without editing any config files:
For example, to shutdown the system at 21:00 today, run:
$ sudo echo "shutdown -h now" | at -m 21:00
atq Command
atq command is used to look at jobs in at command queue:
$ atq
atrm Command
atrm command is used to remove/delete jobs (identified by their job number) from at command queue:
$ atrm 2
awk Command
awk is a programming language created for text processing and is mostly used as a data extraction and reporting tool.
$ awk '//{print}'/etc/hosts
batch Command
batch is another tool to schedule tasks to run at a future time, similar to the at command.
basename Command
basename command is used to print the name of a file stripping of directories in the absolute path:
$ basename bin/findhosts.sh
bg Command
bg is a command that sends a process to the background.
$ tar -czf home.tar.gz .
$ bg
$ jobs
bzip2 Command
bzip2 command is useful to compress or decompress file(s).
$ bzip2 -z filename #Compress
$ bzip2 -d filename.bz2 #Decompress
cal Command
The cal command prints a calendar on the standard output.
$ cal
cat Command
cat command is useful for viewing contents of a file or concatenate files, or data provided on standard input, and displaying it on the standard output.
$ cat file.txt
chgrp Command
chgrp command is used to alter the group ownership of a file. Make the new group name its first argument and the name of the file as the second argument, such as:
$ chgrp cloudinstitute users.txt
chmod Command
chmod command is useful to update file access permissions.
$ chmod +x sysinfo.sh
chown Command
chown command updates the user and group ownership of a file/directory, as shown:
$ chmod -R www-data:www-data /var/www/html
cksum Command
cksum command is useful to display the CRC checksum and byte count of an input file.
$ cksum README.txt
clear Command
clear command allows you to clear the terminal screen.
$ clear
cmp Command
cmp performs a byte-by-byte comparison of two files, like so:
$ cmp file1 file2
comm Command
comm command is useful to compare two sorted files line-by-line.
$ comm file1 file2
cp Command
cp command is for copying files and directories from one location to another.
$ cp /home/cloudinstitute/file1 /home/cloudinstitute/Personal/
date Command
date command is used to display/set the system date and time.
$ date
$ date --set="3 FEB 2020 11:00:00"
df Command
df command is for showing file system disk space usage.
$ df -h
diff Command
diff command is useful to compare two files line by line. It can also be used to locate the difference between two directories in Linux, as shown here:
$ diff file1 file2
dir Command
dir command works similar to Linux ls command; it lists the contents of a directory.
$ dir
dmidecode Command
dmidecode command is a helpful tool for retrieving hardware information of any Linux system. It drops a computer’s DMI (a.k.a SMBIOS) table contents in a human-readable format for simple retrieval.
To view system hardware info, type:
$ sudo dmidecode --type system
du Command
du command is used to show disk space usage of files in a directory and its sub-directories:
$ du /home/johndoe
echo Command
echo command prints a line of text provided to it.
$ echo “This is CloudInstitute - Linux How Tos”
env Command
env command lists all current environment variables and can also set them.
$ env
exit Command
exit command is will allow you to exit a shell.
$ exit
expr Command
expr command can calculate an expression.
$ expr 20 + 30
Take Linux certification training courses with CloudInstitute.io, offering over 200+ courses in top cloud technologies including AWS, Azure, and GCP among others. Start your 30-day free trial today!
factor Command
factor command will show the prime factors of a number.
$ factor 10
find Command
find command allows you to search for files in a directory and its sub-directories. It looks for files by attributes, such as users, groups, permissions, date, file type, size and other criteria.
$ find /home/cloudinstitute/ -name cloudinstitute.txt
free Command
free command displays the system memory usage (used, free, cached, swapped, etc.) in the system, including swap space. Use the -h option to show output in human-friendly format.
$ free -h
grep Command
grep command finds a specified pattern in a file (or files) and shows output lines containing that pattern, like so:
$ grep ‘cloudinstitute’ domain-list.txt
groups Command
groups command shows all names of groups a user is in.
$ groups
$ groups cloudinstitute
gzip Command
Gzip will compress a file, replacing it with one having a .gz extension, as in the following:
$ gzip passwds.txt
$ cat file1 file2 | gzip > foo.gz
gunzip Command
gunzip expands or restores files compressed with the gzip command.
$ gunzip foo.gz
head Command
head command will show first lines (10 lines by default) of the specified file or stdin to the screen:
# ps -eo pid,ppid,cmd,%mem,%cpu --sort=-%mem | head
history Command
history command can show previously used commands or helps you gain info about commands executed by a user.
$ history
hostname Command
hostname command will print or set a system hostname in Linux.
$ hostname
$ hostname NEW_HOSTNAME
hostnamectl Command
hostnamectl command controls the system hostname under systemd. It can print or modify the system hostname and all related settings.
$ hostnamectl
$ sudo hostnamectl set-hostname NEW_HOSTNAME
hwinfo Command
hwinfo will probe for the hardware present in a Linux system:
$ hwinfo
id Command
id command displays user and group information for the current user or specified username.
$ id cloudinstitute
ifconfig Command
ifconfig command can configure a Linux system’s network interfaces. It will configure, view and control network interfaces.
$ ifconfig
$ sudo ifconfig eth0 up
$ sudo ifconfig eth0 down
$ sudo ifconfig eth0 172.16.25.125
ionice Command
ionice command can set or view the process I/O scheduling class and priority of the specified process.
If used without any options, it will query the current I/O scheduling class and priority for that process.
$ ionice -c 3 rm /var/logs/syslog
iostat Command
iostat shows CPU and input/output statistics for devices and partitions. It creates helpful reports for updating system configurations to help balance the input/output load between physical disks.
$ iostat
ip Command
ip command will display or manage devices, routing, policy routing and tunnels. It also works as a substitute for the ifconfig command.
This command will assign an IP address to a specific interface (eth1 in this case).
$ sudo ip addr add 190.150.42.90 dev eth1
iw Command
iw command manages wireless devices and their configuration.
$ iw list
iwlist Command
iwlist command shows detailed wireless information from a wireless interface. The command below helps you get detailed information about the wlp1s0 interface.
$ iwlist wlp1s0 scanning
kill Command
kill command will kill a process with its PID by sending a signal to it (default signal for kill is TERM).
$ kill -p 2300
$ kill -SIGTERM -p 2300
killall Command
killall command can kill a process by its name.
$ killall safari
kmod Command
kmod command manages Linux kernel modules. To list all currently loaded modules, type:
$ kmod list
last Command
last command shows a listing of last logged in users.
$ last
ln Command
ln command can create a soft link between files using the -s flag.
$ ln -s /usr/bin/lscpu cpuinfo
locate Command
locate command will find a file by name. The locate utility works faster and better than it’s find counterpart.
The command below will find a file by its exact name (not *name*):
$ locate -b '\domain-list.txt'
login Command
login command will create a new session with the system. You’ll be asked to provide a username and a password to login.
$ sudo login
ls Command
ls command will list contents of a directory. It works more or less like dir command.
The -l option allows a long listing format.
$ ls -l file1
lshw Command
lshw command is a tool to access detailed information on the hardware configuration of the machine. Invoke it with superuser privileges to access comprehensive information.
$ sudo lshw
lscpu Command
lscpu command shows a system’s CPU architecture information (like the number of CPUs, cores, sockets, threads and more).
$ lscpu
lsusb Command
lsusb command displays information about USB buses in the system and the devices connected to them.
$ lsusb
man Command
man command will view the on-line reference manual pages for commands/programs.
$ man du
$ man df
md5sum Command
md5sum command can compute and print the MD5 message digest of a file. If run without any arguments, debsums checks every single file on your system against the stock md5sum files:
$ sudo debsums
mkdir Command
mkdir command will create one or more directories if they do not already exist (this can be overridden with the -p option).
$ mkdir cloudinstitute-files
OR
$ mkdir -p cloudinstitute-files
more Command
more command allows you to view through relatively lengthy text files one at a time.
$ more file.txt
mv Command
mv command will rename files or directories. It can also move a file or directory to another location in the directory structure.
$ mv test.sh sysinfo.sh
nano Command
nano is a common small, free and friendly text editor for Linux. It’s a clone of Pico, which is the default editor included in the non-free Pine package.
To open a file using nano, type:
$ nano file.txt
netstat Command
netstat command shows useful information concerning the Linux networking subsystem (interface statistics, network connections, routing tables, masquerade connections, and multicast memberships).
This command shows all open ports on the local system:
$ netstat -a | more
nice Command
nice command shows or changes the nice value of a running program. It runs a specified command with an adjusted niceness. When run without any command specified, it prints the current niceness.
The following command starts the process “tar command” setting the “nice” value to 12.
$ nice -12 tar -czf backup.tar.bz2 /home/*
nmap Command
nmap is an open-source tool for network scanning and security auditing. It’s used to quickly scan large networks, but it also works fine against single hosts.
The command below will probe open ports on all live hosts on the specified network.
$ nmap -sV 192.168.56.0/24
nproc Command
nproc command displays the number of processing units present to the current process. Its output may be less than the number of online processors on a system.
$ nproc
passwd Command
passwd command will create/update passwords for user accounts. It can also change the account password validity period. However, normal system users may only change the password of their own account, but root may modify the password for any account.
$ passwd cloudinstitute
pidof Command
pidof shows the process ID of a running program/command.
$ pidof init
$ pidof cinnamon
ping Command
ping command will determine connectivity between hosts on a network:
$ ping google.com
ps Command
ps displays helpful information about active processes running on a system. The example below displays the top running processes by highest memory and CPU usage.
# ps -eo pid,ppid,cmd,%mem,%cpu --sort=-%mem | head
pstree Command
pstree shows running processes as a tree that is rooted at either PID or init if PID is omitted.
$ pstree
pwd Command
pwd command shows the name of the current/working directory.
$ pwd
reboot Command
reboot command can be used to halt, power-off or reboot a system.
$ reboot
rename Command
rename command will rename many files at once. If you have a collection of files with an “.html” extension and you want to rename all of them with the “.php” extension, you can type the following command.
$ rename 's/\.html$/\.php/' *.html
rm command
rm command will remove files or directories.
$ rm file1
$ rm -rf my-files
rmdir Command
rmdir command can delete/remove empty directories.
$ rmdir /backup/all
shutdown Command
shutdown command schedules a time for the system to be powered down. It can halt, power-off or reboot the machine.
$ shutdown --poweroff
sleep Command
sleep command will delay or pause (the execution of a command) for a specified amount of time.
$ check.sh; sleep 5; sudo apt update
sort Command
sort command will sort lines of text in the specified file(s) or from stdin.
$ cat words.txt
split Command
split will split a large file into small chunks.
$ tar -cvjf backup.tar.bz2 /home/cloudinstitute/Documents/*
stat Command
stat will show a file or file system status (-f will specify a filesystem).
$ stat file1
su Command
su command can switch to another user ID or become root during a login session. However, when su is invoked without a username, it defaults to becoming root.
$ su
$ su cloudinstitute
sum Command
sum command will show the checksum and block counts for each each specified file on the command line.
$ sum output file.txt
tac Command
tac command concatenates and shows files in reverse. It basically prints each file to standard output, showing the last line first.
$tac file.txt
talk Command
talk command will help you talk to another system/network user. To talk to a user on the same machine, use their login name. To talk to a user on another machine, use ‘user@host’.
$ talk person [ttyname]
OR
$ talk‘user@host’ [ttyname]
tar Command
tar command is a utility for archiving files in Linux.
$ tar -czf home.tar.gz .
tee Command
tee command will read from standard input and prints to standard output and files.
$ echo "Testing how tee command works" | tee file1
tree Command
The tree command is a small, cross-platform command-line program that can recursively list or display the content of a directory in a tree-like format.
$ tree
time Command
time command runs programs and summarizes system resource usage.
$ time wc /etc/hosts
top Command
top program shows all processes on a Linux system in regards to memory and CPU usage and creates a dynamic real-time view of a running system.
$ top
touch Command
touch command changes file timestamps. It can also be used to create a file, like in the following:
$ touch file.txt
tr Command
tr command is a great utility used to translate (change) or delete characters from stdin, and write the result to stdout or send to a file.
$ cat domain-list.txt | tr [:lower:] [:upper:]
uname Command
uname command shows system information, like the operating system, network node hostname kernel name, version and release, etc.
Use the -a option to show all the system information:
$ uname
uniq Command
uniq command shows or omits repeated lines from input (or standard input). To indicate the number of occurrences of a line, use the -c option.
$ cat domain-list.txt
users Command
users command displays the user names of users currently logged in to the current host.
$ users
vim/vi Command
vim (Vi Improved) is a text editor on Unix-like operating systems. It edits all kinds of plain text and program files.
$ vim file
w Command
w command shows system uptime, load averages and information about the users currently on the machine, and what they are doing (their processes).
$ w
wall Command
wall command will send/display a message to all users on the system.
$ wall “This is TecMint – Linux How Tos”
wc Command
wc command will display newline, word and byte counts for each file specified; also a total for many files.
$ wc filename
whatis Command
whatis command finds and shows a short or one-line manual page descriptions of the provided command name(s).
$ whatis wget
which Command
which command shows the absolute path (pathnames) of the files (or possibly links) that would be executed in the current environment.
$ which who
who Command
who command displays info about users who are currently logged in.
$ who
whereis Command
whereis command helps locate the binary, source and manual files for commands.
$ whereis cat
yes Command
yes command can show a string repeatedly until when terminated or killed using [Ctrl + C] as follows.
$ yes "This is CloudInstitute - Linux HowTos"
zcmp/zdiff Command
zcmp and zdiff are utilities used to compare compressed files.
$ zcmp domain-list.txt.zip basic_passwords.txt.zip
$ zdiff domain-list.txt.zip basic_passwords.txt.zip
zip Command
zip is a simple and easy-to-use utility that packages and compresses (archive) files.
$ tar cf - . | zip | dd of=/dev/nrst0 obs=16k
$ zip inarchive.zip foo.c bar.c --out outarchive.zip
$ tar cf - .| zip backup –
If you are a cloud expert who wants to gain expertise in Linux, getting Docker Training with CloudInstitute.io would be a great step towards success.
We hope you found this short Linux command sheet useful. Connect with our experts to learn more about Linux and the training offered by CloudInstitute.io. Start your 30-day free trial to gain access to over 200 cloud certification training courses with CloudInstitute.io.