Linux Commands
Edit me
Commands are directives to a command-line interpreter or a shell. Commands usually accept command-line arguments such as the target path of an operation or options to alter the operation of the command. There are two types of commands: shell builtins and external programs. Shell builtins usually implement simple or trival functions and are executed directly within the shell, whereas external programs are loaded and executed in a separate process.
Basic Commands
- ls, cp, mv, ps, kill, echo, cat, man, ifconfig
File Management
cd dir
– Change current directory to dirpwd
– Print path of current working directory- pushd, popd
ls -l
– print directory listing of current directory in long formatln -s target link-name
– Create a symbolic link named link-name that points to target- readlink
cp file1 file2
– Copy file1 to file2cp -r src dest
– Copy directory src to destmv file1 file2
– Move or rename file1 to file2rm -f file(s)
– Delete file(s)rm -rf dir
– Remove directory dir and all of its contentsmkdir dir
– Create a directory named dirmkdir -p foo/bar/baz
– Create a directory and all intermediate directories- mknod, mkfifo
touch file
– Create an empty file named filedf -h
– Show disk free spacedu -sh dir
– Show cumulative size of a directory- stat, file
chmod octal file
– Change the permissions of file to octalchmod 777 file
– make file readable, writable, and executable (rwx) for all userschmod +x file
– make file executablechown user path
– Change owner of file or directorychown user:group
– Change owner and group of file or directorychown -R user dir
– Change owner of directory and contents (recursively)- chgrp
cat file
– Display the contents of filemore file
– Display file one page at a time; press spacebar to proceed to the next pageless file
– less is similar to more, but also allows moving backwardshead -20 file
– Display the first 20 lines of filetail -f file
– Display the contents of file as it grows – This is especially usefull for following log files.- vi, vim, nano, pico, emacs
which command
– give the full path to commandfind dir -type f -name 'foo*'
– find all files in dir whose name starts with “foo” (note the single quotes, otherwise shell globing would occur)find . -type f -exec grep -l "foo" {} \;
– find all files in the current directory containing “foo”locate file
– find filediff -u file1 file2
– view the differences between two filesdiff -ur dir1 dir2
– view the differences between two directories
File System and Partitioning
- mount, umount
- lsblk, blockdev, fdisk, fsck, mkfs, resize2fs
Text and Stream Processing
strings file
– print all human readable strings in a binary filegrep pattern file
– find all lines in file that contain or match pattern- dd
- pv, tee
- sed, awk, tr, cut, join, column, iconv
wc -l file
– count number of line in file- nl, od, sort, uniq, fold, tac
- csplit, split
- xargs
File Compression
tar zcvf archive.tar.gz files...
– create a gzip-compressed archivetar zxvf archive.tar.gz
– decompress and extract archived files to current directorygzip file.txt
– compresses a file (creates file.txt.gz) and removes the original, uncompressed versiongunzip file.txt.gz
– uncompresses a file that was compressed withgzip
orcompress
and removes the compressed versionzip -r archive.zip files...
– create a zip archiveunzip archive.zip [-d destination_folder]
– extract/decompress zip achiveunzip -l archive.zip
– list the contents of archive.zip- zcat, zless, zmore, zgrep, zdiff – these ‘Z’ commands operate on gzip-compressed files and provide a ‘Z’ equivalent to their regular counterparts
zcat system.log.0.gz
– view a compressed filezcat
is identical togunzip -c
zless system.log.0.gz
– ‘Z’ equivalent of less to view a compressed file
Getting Help
man command
– Show the manual for commandhelp command
– Use help for builtin commands- If you do not know if a command is a shell builtin or not, run
type command
.
- If you do not know if a command is a shell builtin or not, run
info command
– for GNU/Linux commands, info often provides a more detailed documentation than the man pageapropos subject
– Search manual pages for subjectman -k
is equivalent to the apropos command
whatis command
– Display one-line manual page descriptions- use
help -d
for a one-line description of a shell builtin
- use
which command
– Show the full path of a commandwhereis command
– locate the binary, source, and manual page files for a command
Process Management
ps aux
– list all processes on the system- top, pstree
- kill, pkill, killall
- disown, nohup
- lsof, fuser
Managing System Services
- service, systemctl
- init, shutdown
User Management
- usermod, useradd, adduser, userdel, passwd
- groupmod, groupadd, gpasswd
whoami
– Show who you are logged in as- id, getent, groups
- who, w, last
Network Commands
ifconfig
– List IP addresses and configuration of network interfaces- ifdown, ifup
dhclient -r eth0
– release current DHCP leasedhclient -v eth0
– obtain IP address from DHCP- ip, route
- iptables
- wpa_supplicant
iwlist
– display information about wireless networks- wpa_cli
- brctl, hostapd
- wget, curl
- ftp
scp -P 5010 foo.txt user@adams204xx.hofstra.edu:/home/user/
– copy local file to linux home directoryscp -P 5010 user@adams204xx.hofstra.edu:/home/user/foo.txt foo.txt
– copy remote file to local system- sftp, tftp, rsync
- ping, nmap, traceroute, arp, tcpdump
nslookup domain
– Perform DNS lookup of domaindig domain
– Perform DNS lookup of domainssh user@host
– Connect to host as userssh-keygen -t rsa -b 4096
– Generate a new SSH key-pairssh-copy-id user@host
– Copy your local key (usually ~/.ssh/id_rsa.pub by default) to the account for user on host to enable key-based (passwordless) authentication into the remote host
System Information
uname -a
– Show kernel information- dmidecode
- lscpu, lspci, lsusb
- hostname
- date, uptime
free
– Show memory and swap usage
Printing
- lp, lpr
Environment
- env, chroot
Shell builtins
- cd, pwd
- clear
- exit
- history, fc
- type