Basic File and Directory Commands:
ls
: List directory contentsls
– lists files in the current directoryls -l
– lists files in long format (permissions, size, owner, etc.)ls -a
– lists all files, including hidden ones (starting with a dot.
)
cd
: Change directorycd [directory]
– change to specified directorycd ..
– move up one level (parent directory)cd /
– move to the root directorycd ~
– move to the home directory
pwd
: Print working directory- Displays the current directory path.
mkdir
: Make directoriesmkdir [directory_name]
– creates a new directory
rmdir
: Remove directoriesrmdir [directory_name]
– deletes an empty directory
rm
: Remove files or directoriesrm [file]
– removes filerm -r [directory]
– removes directory recursivelyrm -rf [directory]
– forcefully removes a directory without prompting
cp
: Copy files or directoriescp [source][destination]
– copies file from source to destinationcp -r [source_directory][destination]
– copies directory recursively
mv
: Move or rename files or directoriesmv [source][destination]
– moves or renames a file or directory
touch
: Create an empty file or update file timestampstouch [filename]
– creates a new file if it doesn’t exist
File Viewing and Manipulation Commands:
cat
: Concatenate and display filescat [file]
– displays the content of a filecat [file1][file2]
– displays the content of both files in order
less
: View file content page by pageless [file]
– allows scrolling through a large file
head
: Display the first lines of a filehead -n [number][file]
– displays the firstn
lines of the file
tail
: Display the last lines of a filetail -n [number][file]
– displays the lastn
lines of the filetail -f [file]
– continuously monitors and displays new lines added to a file (useful for log monitoring)
grep
: Search for patterns within filesgrep [pattern][file]
– searches for a pattern in a filegrep -r [pattern][directory]
– searches recursively in a directory
File Permissions and Ownership Commands:
chmod
: Change file permissionschmod [permissions][file]
– modifies the permission of a filechmod u+x [file]
– gives the user execution rights for the file
chown
: Change file ownershipchown [owner][file]
– changes the ownership of the file
chgrp
: Change group ownership of a filechgrp [group][file]
– changes the group ownership of the file
Process and System Management Commands:
ps
: View currently running processesps
– displays processes running in the current sessionps -aux
– shows detailed information about all running processes
top
: Real-time view of system processes- Displays real-time information about running processes, CPU, and memory usage
kill
: Terminate processeskill [PID]
– sends the terminate signal to a process with a specific Process ID (PID)kill -9 [PID]
– forcefully kills a process
htop
: Interactive process viewer (requires installation)htop
– a more interactive and user-friendly version oftop
df
: Show disk space usagedf -h
– displays disk usage in human-readable format
du
: Show directory space usagedu -sh [directory]
– shows the size of the specified directory
free
: Check memory usagefree -h
– displays memory and swap usage in human-readable format
uname
: Display system informationuname -a
– displays detailed information about the system (kernel version, architecture, etc.)
Networking Commands:
ping
: Test network connectivityping [hostname/IP]
– sends ICMP packets to a host to test connectivity
ifconfig
/ip
: Network interface configurationifconfig
– displays network interface information (Linux pre-2019, now deprecated in favor ofip
)ip addr
– displays IP address and network details
netstat
: Display network connections and listening portsnetstat -tuln
– displays TCP/UDP listening ports
curl
: Transfer data to or from a servercurl [URL]
– makes HTTP requests to a URL and retrieves the content
wget
: Download files from the webwget [URL]
– downloads a file from the specified URL
Archive and Compression Commands:
tar
: Archive and extract filestar -cvf [archive.tar][file/directory]
– creates an archivetar -xvf [archive.tar]
– extracts the contents of an archive
gzip
/gunzip
: Compress and decompress filesgzip [file]
– compresses the filegunzip [file.gz]
– decompresses the file
zip
/unzip
: Compress and decompress files in zip formatzip [archive.zip][file]
– compresses file into a zip archiveunzip [archive.zip]
– extracts a zip archive
User and Group Management:
whoami
: Display the current user- Shows the currently logged-in user.
adduser
/useradd
: Add a new useradduser [username]
– adds a new user (simpler, with prompts)useradd [username]
– adds a new user (requires manual configuration)
passwd
: Change user passwordpasswd [username]
– sets or changes the password for the user
groups
: Display group membershipgroups [username]
– shows the groups a user belongs to
Text Manipulation Commands:
echo
: Print text to the screenecho [text]
– prints the provided text
sort
: Sort lines in a filesort [file]
– sorts the lines in the file
uniq
: Remove duplicate lines from a fileuniq [file]
– removes adjacent duplicate lines
cut
: Extract sections from a filecut -d [delimiter] -f [fields][file]
– extracts specific fields based on delimiter
wc
: Word countwc -l [file]
– counts the number of lines in a file
awk
: Pattern scanning and processing language- Used to manipulate data and generate reports.
sed
: Stream editor for modifying filessed 's/old/new/g' [file]
– replaces all occurrences ofold
withnew
in a file
Package Management Commands:
apt
/apt-get
(Debian-based systems):apt-get update
– update package listsapt-get install [package]
– install a package
yum
/dnf
(Red Hat-based systems):yum install [package]
– install a package