terminal
Frequently used shell commands for file navigation, permissions, networking and more.
Navigation
Moving around the file system.
pwd
Print working directory (shows your current location).
pwdcd [directory]
Change directory.
cd Documentsls
List files and directories.
lsls -l
List files and directories with details.
ls -lls -a
List all files and directories (including hidden ones).
ls -acd ..
Go up one directory.
cd ..cd ~
Go to your home directory.
cd ~File Manipulation
Creating, moving, and deleting files and directories.
touch [file]
Create an empty file.
touch myfile.txtmkdir [directory]
Create a new directory.
mkdir mydirectorycp [source] [destination]
Copy a file or directory.
cp myfile.txt mycopy.txtmv [source] [destination]
Move or rename a file or directory.
mv myfile.txt newlocation/myfile.txtrm [file]
Remove a file.
rm myfile.txtrm -r [directory]
Remove a directory and its contents (recursive).
rm -r mydirectoryrm -f [file]
Force remove a file (use with caution!).
rm -f myfile.txtrm -rf [directory]
Force remove a directory and its contents (use with extreme caution!).
rm -rf mydirectoryViewing Files
Displaying the contents of files.
cat [file]
Display the contents of a file.
cat myfile.txtless [file]
View a file one page at a time (use space to scroll, q to quit).
less myfile.txthead [file]
Display the first few lines of a file.
head myfile.txttail [file]
Display the last few lines of a file.
tail myfile.txtnano [file]
Open a file in the nano text editor.
nano myfile.txtvi/vim [file]
Open a file in the vi/vim text editor.
vi myfile.txtSearching
Finding files and content.
find [directory] [options] [expression]
Find files and directories.
find . -name "myfile.txt"grep [pattern] [file]
Search for a pattern in a file.
grep "hello" myfile.txtwhich [command]
Show the location of a command.
which lsFile Permissions and Ownership
Managing file access rights and ownership.
# chmod numeric permissions overview:# Each digit represents permissions for: [Owner][Group][Others]# Add values for read(4), write(2), execute(1)## Examples:# 7 = 4+2+1 = read, write, execute# 6 = 4+2 = read, write# 5 = 4+1 = read, execute# 4 = 4 = read# 3 = 2+1 = write, execute# 2 = 2 = write# 1 = 1 = execute# 0 = none## Common chmod values:# 755 = rwx for owner, rx for group, rx for others# 644 = rw for owner, r for group, r for others# 700 = rwx for owner, none for group/otherschmod [mode] [file]
Change file permissions (numeric or symbolic).
chmod 644 myfile.txtchmod +x [file]
Make a file executable.
chmod +x script.shchown [owner]:[group] [file]
Change file owner and group.
chown user:staff myfile.txtls -l
View file permissions and ownership.
ls -lstat [file]
Show detailed file status including permissions and ownership.
stat myfile.txtSystem Information
Getting information about the system.
uname -a
Display system information.
uname -adf -h
Display disk space usage.
df -hdu -sh [directory]
Display directory size.
du -sh Documentstop
Display running processes.
topps aux
List all running processes.
ps auxkill [pid]
Terminate a process by its PID.
kill 1234kill -9 [pid]
Force kill a process by its PID.
kill -9 1234pkill [name]
Kill processes by name.
pkill firefoxsystemctl status [service]
Show status of a systemd service.
systemctl status nginxsystemctl restart [service]
Restart a systemd service.
systemctl restart nginxNetworking
Commands related to network operations.
ping [host]
Check network connectivity to a host.
ping google.comifconfig
Display network interface information (macOS/Linux).
ifconfigipconfig
Display network interface information (Windows).
ipconfignetstat
Display network connections.
netstatcurl [url]
Transfer data from or to a server.
curl https://www.example.comwget [url]
Download a file from a URL.
wget https://www.example.com/file.zipArchiving and Compression
Creating and extracting tarballs and zip files.
# tar common flags overview:# c = create new archive# x = extract archive# v = verbose (show files being processed)# f = specify filename of archive# z = compress with gzip (.tar.gz)# j = compress with bzip2 (.tar.bz2)# J = compress with xz (.tar.xz)## Examples:# tar -cvf archive.tar files/ -> create tar# tar -xvf archive.tar -> extract tar# tar -czvf archive.tar.gz dir/ -> create gzipped tar# tar -xzvf archive.tar.gz -> extract gzipped tartar -cvf [archive.tar] [files]
Create a tar archive from files or directories.
tar -cvf archive.tar myfoldertar -xvf [archive.tar]
Extract a tar archive.
tar -xvf archive.tartar -czvf [archive.tar.gz] [files]
Create a compressed tarball (gzip).
tar -czvf archive.tar.gz myfoldertar -xzvf [archive.tar.gz]
Extract a gzipped tarball.
tar -xzvf archive.tar.gzzip [archive.zip] [files]
Create a zip archive.
zip archive.zip myfile.txt myfolder/*unzip [archive.zip]
Extract a zip archive.
unzip archive.zip