100 Basic Linux Commands đ
January 30, 2021â˘1,227 words
Execute the previous command used:
!!Execute a previous command starting with a specific letter. Example:
!sShort way to copy or backup a file before you edit it. For example, copy nginx.conf
cp nginx.conf{,.bak}Toggle between current directory and last directory
cd -Move to parent (higher level) directory. Note the space!
cd ..Go to home directory
cd ~Go to home directory
cd $HOMEGo to home directory (when used alone)
cdSet permissions to 755. Corresponds to these permissions: (-rwx-r-x-r-x), arranged in this sequence: (owner-group-other)
chmod 755 <filename>Add execute permission to all users.
chmod a+x <filename>Changes ownership of a file or directory to .
chown <username>Make a backup copy of a file (named file.backup)
cp <file> <file>.backupCopy file1, use it to create file2
cp <file1> <file2>Copy directory1 and all its contents (recursively) into directory2
cp -r <directory1> <directory2>/Display date
dateZero the sdb drive. You may want to use GParted to format the drive afterward. (Requires sudo).
dd if=/dev/zero of=/dev/sdbDisplay disk space usage
df -hTake detailed messages from OS and input to text file
dmesg>dmesg.txtDisplay a LOT of system information. I usually pipe output to less. You need elevated permissions to run this (sudo).
dmidecodeDisplay BIOS information. You need elevated permissions to run this (sudo).
dmidecode -t 0Display CPU information. You need elevated permissions to run this (sudo).
dmidecode -t 4Search for installed packages related to Apache
dpkg âget-selections | grep apacheShows you where in the filesystem the package components were installed
dpkg -L <package_name>Display detailed disk use for each subdirectory
du / -bh | lessPrint the environment variable PATH
echo $PATHDisplay environment variables like USER, LANG, SHELL, PATH, TERM, etc.
envOpens a picture with the Eye of Gnome Image Viewer
eog <picture_name>Quit the terminal (or give up super-powers if youâve previously done sudo su)
exitDisplay memory usage
freeEasy way to view all the system logs.
gnome-system-logSearch through file(s) and display lines containing matching string
grep <string> <filename>Get the number of seconds since the OS was started
grep btime /proc/stat | grep -Eo "[[:digit:]]+"Display the last 1000 commands
history | lessDisplay the name of the local host
hostnameDisplay time.
hwclock âshowDisplay user id (uid) and group id (gid)
idDisplay your local IP address and netmask
ifconfigWireless network interface
iwconfigDisplay wireless network information
iwlistKill process by name. You need elevated permissions to run this (sudo).
killall processGet 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}"Quit shell session (only for a shell youâve logged into like one of the virtual consoles)
logoutList non-hidden files and subfolders in current directory (like dir for windows). Use -R for recursive and -a to include hidden files.
lsDisplay 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 <filename>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 | lessDisplay more networking information
lshw -C networkDisplay kernel modules currently loaded
lsmodDisplay sound, video, and networking hardware
lspci -nv | lessDisplay usb-connected hardware
lsusbRead the commandâs man page (manual)
man <command>Create new directory at specified location
mkdir <dirname>Move file to specified directory
mv <file> <dir>Rename file1 to file2
mv <file1> <file2>Display routing table
netstat -rnPrint environmental variables
printenvList the processes currently running by this user. There are many useful options, view them with ps âhelp
ps -AfPrint working directory
pwdDelete file
rm <filename>Delete directory and all itâs contents
rm -rf <dir>Removes all files that end in txt in current directory
rm *.txtDelete directory (will only work if itâs empty)
rmdir <dir>Display your default gateway listed under âdefaultâ
routeCompletely 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 <file>Shutdown now.
shutdown -h nowRestart now.
shutdown -r nowLog into remote computer
ssh <IP address>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 -iOpen 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 suCreates a compressed archive of the specified directory and all files/directories under it.
tar czf <dirname>.tgz <dirname>Expand the contents of a compressed archive and extract to current directory.
tar zxvf <archive>List current processes by cpu use. This is very useful. Press q to quit and h for help.
topCreate an empty file if it doesnât exist
touch <filename>Display the name of the current terminal
ttyDisplay your linux kernel
uname -aDisplay your machineâs processor architecture
uname -mReturns one-line synopsis from the commandâs man page
whatis <command>Returns the location of the program in the filesystem
whereis <command>Returns the applicationâs path
which <command>Display the users logged into the machine
whoDisplay your login name
whoamiThis will display the output of test.log as it is being written to by another program
tail âfollow test.logIf 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
./filename.txtEscape operator. Use it before a space if youâre trying to open a file that has whitespace in the name.
\The tilde represents your home directory.
~Run any command when the system load is low
batch <command>Display cpu info
cat /proc/cpuinfoDisplay memory usage
cat /proc/meminfoDisplay networking devices
cat /proc/net/devDisplay performance information
cat /proc/uptimeDisplay kernel version
cat /proc/versionDisplay file contents
cat <filename>List partition tables
fdisk -lShow the properties/compression of a file or package
file <package_name>Find a file. Search Linux filesystem for a file name.
find / -name <filename>To create a *.gz compressed file
gzip test.txtTo uncompress a *.gz file
gzip -d test.txt.gzDisplay compression ratio of the compressed file using gzip -l
gzip -l *.gzOutput file status
stat filename.txtDownload a file from the internet
wget http://remote_file_urlShow list of last 10 logged in users.
last -n 10Display a tree of processes
pstree