101 Linux Commands

Some of these commands require elevated permissions (sudo) to run.

101

Linux Commands

!!Execute the previous command used: 
! cd ..Move to parent (higher level) directory. 
cd ~Go to home directory 
 !sExecute a previous command starting with a specific letter.
cpcopy or backup a file cp nginx.conf{,.bak}
cd –Toggle between current directory and last directory
cd $HOMEGo to home directory 
cdGo to home directory 
chmod 755 Set permissions to 755. Corresponds to these permissions: (-rwx-r-x-r-x), arranged in this sequence: (owner-group-other) 
chmod a+x Add execute permission to all users. 
chown 
cp .backupMake a backup copy of a file (named file.backup) 
cpCopy file1, use it to create file2 
cp -r /Copy directory1 and all its contents (recursively) into directory2 
dateDisplay date 
dd if=/dev/zero of=/dev/sdbZero the sdb drive
 df -hDisplay disk space usage
dmesg>dmesg.txtTake detailed messages from OS and input to text file 
dmidecodeDisplay a LOT of system information
dmidecode -t 0Display BIOS information. 
dmidecode -t 4Display CPU information. 
dpkg –get-selections | grep apacheSearch for installed packages related to Apache 
dpkg -LShows you where in the filesystem the package components were installed 
du / -bh | lessDisplay detailed disk use for each subdirectory 
echo $PATHPrint the environment variable PATH 
eogOpens Eye of Gnome
exitQuit the terminal 
freeDisplay memory usage 
gnome-system-log view all the system logs.
grepSearch through file(s) and display lines containing matching string 
grep btime /proc/stat | grep -Eo “[[:digit:]]+”Get the number of seconds since the OS was started 
history | lessDisplay the last 1000 commands 
hostname Display the name of the local host 
 hwclock –showDisplay time.
idDisplay user id (uid) and group id (gid) 

33. 

34.

35. 

36. 

37. Display your local IP address and netmask ifconfig

38. Wireless network interface iwconfig

39. Display wireless network information iwlist

40. Kill process by name. You need elevated permissions to run this (sudo). killall process

41. Get the date and time of the last system shutdown last -x | grep shutdown | head -1 | grep -Eo “[A-Z][a-z]{2} [[:digit:] ][[:digit:]] [[:digit:]]{2}:[[:digit:]]{2}”

42. Quit shell session (only for a shell you’ve logged into like one of the virtual consoles) logout

43. List non-hidden files and subfolders in current directory (like dir for windows). Use -R for recursive and -a to include hidden files. ls

44. Display file access permissions for all files in the current directory. The format for permissions is drwxrwxrwx where the order is owner-group-other and the numeric values are read=4, write=2, execute=1. ls -l

45. List all available applications, in case you’ve forgotten how to open Open Office Writer or another application from the terminal (oowriter) ls /usr/bin | less

46. Display more networking information lshw -C network

47. Display kernel modules currently loaded lsmod

48. Display sound, video, and networking hardware lspci -nv | less

49. Display usb-connected hardware lsusb

50. Read the command’s man page (manual) man

51. Create new directory at specified location mkdir

52. Move file to specified directory mv

53. Rename file1 to file2 mv

54. Display routing table netstat -rn

55. Print environmental variables printenv

56. List the processes currently running by this user. There are many useful options, view them with ps –help ps -Af

57. Print working directory pwd

58. Delete file rm

59. Delete directory and all it’s contents rm -rf

60. Removes all files that end in txt in current directory rm *.txt

61. Delete directory (will only work if it’s empty) rmdir

62. Display your default gateway listed under “default” route

63. Completely destroy all traces of the file. This takes a while. -n 7 means seven overwrites, -z means zero the bits afterward to hide shredding, -u means delete the file when done, and -v means verbose. shred -zuv -n 7

64. Shutdown now. shutdown -h now

65. Restart now. shutdown -r now

66. Log into remote computer ssh

67. Open the root shell, giving yourself superuser permissions until you relegate your powers with exit. Unlike sudo su which does the same thing, this method of starting the root shell is uncorrupted by a user’s environmental variables. sudo -i

68. Open the root shell, like sudo -i, but this method retains the user’s environmental variables. Relegate superuser permissions and return to normal shell with exit. sudo su

69. Creates a compressed archive of the specified directory and all files/directories under it. tar czf .tgz

70. Expand the contents of a compressed archive and extract to current directory. tar zxvf

71. List current processes by cpu use. This is very useful. Press q to quit and h for help. top

72. Create an empty file if it doesn’t exist touch

73. Display the name of the current terminal tty

74. Display your linux kernel uname -a

75. Display your machine’s processor architecture uname -m

76. Returns one-line synopsis from the command’s man page whatis

77. Returns the location of the program in the filesystem whereis

78. Returns the application’s path which

79. Display the users logged into the machine who

80. Display your login name whoami

81. This will display the output of test.log as it is being written to by another program tail –follow test.log

82. If you’ve just navigated to a directory shell and want to open a file or application IN that directory. Just use this command followed by the filename eg. ./filename.txt

83. Escape operator. Use it before a space if you’re trying to open a file that has whitespace in the name. \

84. The tilde represents your home directory. ~

85. Run any command when the system load is low batch

86. Display cpu info cat /proc/cpuinfo

87. Display memory usage cat /proc/meminfo

88. Display networking devices cat /proc/net/dev

89. Display performance information cat /proc/uptime

90. Display kernel version cat /proc/version

91. Display file contents cat

92. List partition tables fdisk -l

93. Show the properties/compression of a file or package file

94. Find a file. Search Linux filesystem for a file name. find / -name

95. To create a *.gz compressed file gzip test.txt 9

6. To uncompress a *.gz file gzip -d test.txt.gz 97. Display compression ratio of the compressed file using gzip -l $ gzip -l *.gz

98. Output file status stat filename.txt 99. Download a file from the internet wget http://remote_file_url

100. Show list of last 10 logged in users. last -n 10

101. Display a tree of processes pstree Note: If you are pasting a command from above that includes a “ or ‘ and it does not work, you may have to re-type those quotes in shell manually.