Basic Operations
sudo: “Super User Do”… run command as root
man: manual… an interface to the system reference manuals
df -h: report file system disk space usage in a human readable format
du -h: estimates file size within a directory
free -h: display amount of free an used memory in the system
uname: “Unix Name”
top: display Linux processes
ps axc: display currently running programs
pidof: get a program’s process ID
kill: terminate a process
history: view command history
echo: display a line of text
date: today’s date
cal: calendar
clear: clear the terminal screen
exit: exit the terminal screen
tmux: terminal multiplexer. allows for multiple windows inside of a single terminal window
Keybinds
CTRL+C: stop any command that is currently running
CTRL+Z: pause any command that is currently running
File Operations
pwd: print working directory… outputs current absolute path
cd: change directory
ls: list directory contents
mkdir: make directory
touch: create a file
cp: copy
mv: move (also used to rename files)
rm: remove… delete a file
rm -rf: remove recursive force… delete a directory and it’s contents
cat: concatenate files / print content of file on the standard output
diff: show the difference between two files
locate: find files by name (use -i to ignore case)
find: search for files in a directory hierarchy
zip, unzip: compress / uncompress files in a zip archive
tail -f: output the last part of files and follow the appended data as the file grows
- log files are the main use case
tar: an archiving utility
archive multiple files into a tarball — a common Linux file format that is similar to zip format, with compression being optional.
Extract a gzipped tarball:
tar -xvzf tarballname.tar.gz
-x --extract = extract files from an archive -v, --verbose = verbosely list files processed -z, --gzip = gzipped files eg. for tar.gz packages -f, --file ARCHIVE = use archive file or device ARCHIVE
chmod: change the read, write, and execute permissions of files and directories
chown: change or transfer the ownership of a file to the specified username
sed: commonly used for find and replace tasks
- Example: find and replace (first instance on every line):
sed 's/find/replace' <oldfile >newfile
- Global find/replace (replaces every instance on every line in a file):
sed "s/c/C/g" filename
- Write directly to the file:
sed -i '' filename.txt
grep: searches for PATTERNS in each FILE. PATTERNS is one or more patterns separated by newline characters, and grep prints each line that matches a pattern.
- Example:
grep 'string' path/to/file
‘string’, [list], ^linestart,
- Exact match:
grep -w 'string' filename
Network Connectivity
wget: the non-interactive network downloader… pass in a link to download a file
curl: transfer a URL.. transfer data to/from servers, with many more options than only HTTP/HTTPS
ping: send ICMP ECHO_REQUEST to network hosts… check your connectivity status to a server
ssh: OpenSSH remote client login. Remote into servers on a network
scp: secure file copy. copies files between hosts on a network
hostname -i: displays hostname and IP address
References
10 basic Linux commands you need to know | Enable Sysadmin
17 Linux commands every sysadmin should know | Enable Sysadmin
34 Linux Basic Commands Every User Should Know (Cheat Sheet)