Misc. Commands' Cheatsheet

Here's a concise cheatsheet for some miscellaneous commands used in Linux.

Command Definition Syntax Example
bc bc is an arbitrary-precision language for performing math calculations. bc [ -hlwsqv ] [long-options] [file] To assign the variable var a value of 5 and display in on the console: echo "var=5;var" | bc
chdir (change directory) chdir is the system command for changing the current working directory. chdir direectory_name To change directory to “/home/etc/ww”: chdir /home/etc/ww
df (disk free) It reports the amount of space used and available on currently mounted filesystems. df [option(s)] [device(s)] To get information only for the root directory: df /
du (disk usage) It shows the sizes of directories and files. du [options] [directories and/or files] This will show the sizes of all directories that are in dir2 that resides in dir1: du dir1/dir2
file This command classifies filesystem objects. file [option(s)] object_name(s) Information about a file named “file1.txt” can be obtained by: file file1.txt
free It provides information about unused and used memory and swap space. free [options] To show all of the data in megabytes: free -m
gzip It is used to compress or decompress files. gzip [options] [suffix] [filename] To decompress a file “file.gz”: gzip -d file.gz
halt This command instructs the hardware to stop all CPU functions. halt [option] sudo halt
hostname Shows or sets a computer’s host name and domain name. hostname [options] [new_host_name] To change the hostname to “host2”: hostname host2
kdesu It opens KDE su, the graphical front end for the su command. kdesu [-u username] [options] command To allow Nautilus (the official file manager for the GNOME desktop) to be run as root during an ordinary user session: kdesu -c nautilus
killall It terminates all processes associated with programs whose names are provided to it as arguments. killall [options] program_name(s) To abruptly terminate nautilus (which is the official file manager for the GNOME desktop): killall nautilus
less less is the more powerful version of more. It allows backward movement in the file as well as forward movement. Also, less does not have to read the entire input file before starting, so with large input files it starts up faster than text editors like vi. less <file name> less /var/log/file
mkfs (make filesystem) It creates a filesystem on a disk or on a partition thereof. mkfs [ -V ] [ -t fstype ] [ fs-options ] filesys [ blocks ] This would create an ext2 filesystem on a formatted floppy disk that has been inserted into the first floppy drive: mkfs /dev/fd0
more more shows information one page at a time. more [filename] To view the directory listing of a file, one page at a time: more file.txt
mv It renames and moves files and directories. mv [options] argument(s) To rename “file1.txt” to “file2.txt”: mv file1.txt file2.txt
pstree It displays the processes on the system in the form of a tree diagram. pstree [options] [pid or username] To show only those branches that have been initiated by a user with a username runner: pstree runner
reboot It restarts a computer without having to turn the power off and back on. reboot [option] reboot
rsync It is a fast copying too. rsync [options] src [dest] rsync -v /var/lib/rpm/file /root/temp/file
runlevel It reports the current and previous runlevels. runlevel [utmp] It is usually used without any options: runlevel
sed (stream editor) It allows you to filter and transform text. sed options [script] [Iimputfile] To replace all instances of “cat” with “dog” in ‘file.txt’ sed 's/cat/dog/g' file.txt
shred It destroys files. shred [option(s)] file(s)_or_devices(s) To securely destroy “file1.txt” and “file2.txt”: shred file1.txt file2.txt
shutdown This command allows you to shutdown a Windows XP, Vista, 7, 8, or 10 computer from the command line, as well as perform additional functions that are not available through Windows. shutdown [option]… TIME [MESSAGE] sudo shutdown 5 ; it will shut down system after 5 minutes.
spell This command checks spellings. spell [options] [file_name(s)] To spell-chek “file.txt” : spell file.txt
strings It returns each string of printable characters in files. strings [options] file_name(s) To display all strings in file1.txt that consist of at least 3 characters: strings -n 3 file1
su (substitute user) It changes a login session’s owner without the owner having to first log out of that session. su [options] [commands] [-] [username] To change the user of current login session to anna: su anna
tar This command is used to archive files in tar format. We can also used this command to convert, maintain, and extract tar files. tar [option(s)] [archive] [file_name(s)] tar -cf my_files.tar file_1 file_2 file_3
tr It translates or deletes characters. tr [options] set1 [set2] To replace every instance of text-typed a with b: tr a b
unalias It removes entries from the current user’s list of aliases. unalias [-a] [alias_name(s)] If a user had an alias named p for the pwd (i.e., present working directory) command, such alias could be removed with: unalias p
uptime It shows the current time, how long the system has been running since it was booted up, how many user sessions are currently open and the load averages. uptime [option] uptime
vim It is used for editing any kind of text and is especially suited for editing computer programs. vim [options] [filelist] To edit a single file: vim file.txt
w w shows who is logged into the system and what they are doing. w [options] [username1, username2, . . .] w ; running this command with no arguments shows the list of users along with their ongoing processes.
whatis It gives very brief descriptions of command line programs and other topics related to Linux and other Unix-like operating systems. whatis keyword(s) whatis sudo
wc (word count) This command counts the number of lines, words and characters that are contained in text. wc [options] [file_name(s)] wc file1 file2
whereis It locates the program, source code, and manual page for a command. whereis program_name(s) whereis ls

Get hands-on with 1400+ tech skills courses.