Jul 31, 2024
ls
ls
: Lists directory contents (similar to dir
in Windows)-l
: Long listing, provides detailed information-a
: Shows hidden files-t
: Sort by modification time-h
: Human-readable file sizesls -lath
-R
: Recursively list subdirectoriescd
cd
: Change directory
cd [directory]
: Navigate to a directorycd -
: Switch to previous directorycd ..
: Move up one directory levelcd
: Go to home directorypwd
: Print working directorytouch
: Create empty files
touch file1 file2 file3
mkdir
: Create directories
mkdir dir1 dir2
mkdir -p parent/child/grandchild
mkdir -m 777 dir
(full rights, not recommended)cp
: Copy files and directories
cp file1 file2
: Copy filecp -R dir1 dir2
: Copy directory recursivelyrm
: Remove files and directories
rm file
: Remove filerm -rf dir
: Recursively and forcibly remove directoryrm *.txt
mv
: Move or rename files
mv oldname newname
: Rename filemv file1 dir/
: Move file to directorydu
du
: Disk usage
du -h
: Human-readable formatdu -sh
: Summary of directory sizechmod
: Change file permissions
chmod [permissions] [file]
chmod u+x file
(add execute permission for owner)chown
: Change file owner and group
chown [owner]:[group] [file]
chown user:group file
cat
: Concatenate and display files
cat file
cat file1 file2 > newfile
cat file >> existingfile
tail
: View end of file
tail file
: Last 10 linestail -n 20 file
: Last 20 linestail -f file
: Follow updates to filehead
: View beginning of file
head file
: First 10 lineshead -n 20 file
: First 20 linesless
: View file one page at a time
/search
to find, q
to quitnano
: Simple text editor
nano file
: Open file in nanovi
: Advanced text editor
vi file
: Open file in vii
to insert, esc
to exit insert mode, :wq
to save and quitps
: Display process status
ps aux
: Detailed view of all processestop
: Dynamic view of system processes
q
: Quitkill
: Terminate processes
kill PID
: Kill process by PIDkill -9 PID
: Force killjobs
: List background jobs
fg %1
: Bring job 1 to foregroundifconfig
: Network interfaces (deprecated)ip
: Newer networking tool
ip a
: Show all IP addressesip route show
: Show routing tableip route add [dest] via [gateway] dev [interface]
ip addr add [IP]/[prefix] dev [interface]
ip addr del [IP]/[prefix] dev [interface]
netstat
: Network statistics (deprecated)
netstat -l
: Show listening portsss
: Socket statistics
ss -t
: Show TCP connectionsss -u
: Show UDP connectionsss -p
: Show process namesssh
: Secure shell
ssh user@host
: Connect to remote host-p [port]
: Specify portscp
: Secure copy
scp sourcefile user@host:/path
: Copy file to remote hostrsync
: Remote synchronization
rsync -av source dest
: Sync directoriesuname -a
: Display system informationdf
: Disk free space
df -h
: Human-readabledf -T
: Show filesystem typefind
: Search for files
find /path -name filename
: Search by namefind /path -size +100M
: Search by sizefind /path -mtime -7
: Search by modification timegrep
: Search within files
grep 'pattern' file
: Search for patterngrep -r 'pattern' /path
: Recursive searchtar
: Archive files
tar czf archive.tar.gz files
: Create compressed archivetar xzf archive.tar.gz
: Extract archivetar rf archive.tar file
gzip
: Compress files
gzip file
: Compress filegunzip file.gz
: Decompress filegzip -l file.gz
: List contents of gzip fileuseradd
: Add user
useradd username
: Create new useruseradd -m username
: Create user with home directoryuseradd -G groupname username
: Add user to groupuseradd -e YYYY-MM-DD username
: Set account expiration dateuserdel
: Delete user
userdel username
: Delete useruserdel -r username
: Delete user and home directorygroupadd
: Add group
groupadd groupname
: Create new groupgroupdel
: Delete group
groupdel groupname
: Delete group