Jul 31, 2024
ls
Command-l
: Long listing format.-a
: Show all files, including hidden ones.-t
: Sort by modification time, newest first.-h
: Human-readable sizes.ls -lath
for detailed info, human-readable sizes, and hidden files.cd
Commandcd -
: Go back to the previous directory.cd ..
: Move up one directory level.cd ~
: Go to the home directory.cd /path/to/dir
: Directly change to a specified directory.Tab
key for auto-completing directory names.pwd
command shows the present working directory.touch
: Create blank files.mkdir
: Create directories.
mkdir -p /path/to/dir
: Creates nested directories in one command.mkdir -m 777 dir
: Set permissions while creating a directory.cp
:
cp source destination
: Copy files.cp -r source destination
: Copy directories recursively.rm
: Remove files.
rm -r directory
: Remove directories and their contents recursively.rm -rf /path
: Forcefully remove files/directories.mv
: Move or rename files and directories.
mv source destination
: Move/rename files or directories.cat
Commandcat file1 file2 > combined_file
.cat file1 >> file2
.less
and more
Commandsless file
: View file with search capability.more file
: Similar to less
but with fewer features.tail
and head
Commandstail
: View the end of the file.
tail -n 15 file
: View the last 15 lines.tail -f file
: Follow file updates in real-time.head
: View the beginning of the file.
head -n 15 file
: View the first 15 lines.vi
/vim
:
i
to insert, :w
to save, :q
to quit.nano
:
Ctrl + X
to exit, Y
to confirm changes.ps
: Display process information.
ps aux
: Detailed information of all processes.top
: Interactive view of running processes.
top -u username
: View processes for a specific user.kill
: Terminate a process.
kill PID
: Terminate a process by PID.kill -9 PID
: Forcefully terminate a process.&
: Run processes in the background.
command &
: Run command in the background.jobs
: List background jobs.fg %job_number
: Bring background job to foreground.ifconfig
: Display network interface information (deprecated).ip
: Modern replacement for ifconfig.
ip addr
: Show IP addresses.ip route
: Display routing table.ip route add
: Add a new route.ip addr add
: Add a new IP address.netstat
: Display network connections, routing tables, interface statistics.
netstat -l
: List listening connections.ss
: Display network socket information.
ss -t
: Show TCP sockets.ss -u
: Show UDP sockets.ss -p
: Show processes using sockets.ssh
: Secure Shell for remote login.
ssh user@hostname
: Connect to a remote server.-p port
: Specify port.scp
: Secure Copy Protocol for transferring files.
scp source user@hostname:/path
: Copy files to a remote server.uname -a
: Display system information.df
: Display disk space usage.
df -h
: Human-readable format.df -T
: Show file system types.find
: Search for files in a directory hierarchy.
find /path -name filename
: Find files by name.-size +1M
: Find files larger than 1MB.-mtime -30
: Find files modified in the last 30 days.grep
: Search inside files.
grep pattern files
: Search for a pattern in files.grep -r pattern /path
: Recursively search.tar
Commandtar -czf archive.tar.gz files
: Create a compressed archive.tar -xvf archive.tar.gz
: Extract files from an archive.tar -rf archive.tar files
: Add files to an existing archive.gzip
Commandgzip file
: Compress a file.gunzip file.gz
: Decompress a file.gzip -l file.gz
: List contents of a compressed file.useradd
: Add a new user.
useradd username
: Basic usage.useradd -m username
: Create home directory.useradd -g groupname username
: Assign user to a group.userdel
: Delete a user.
userdel username
: Basic usage.userdel -r username
: Remove user and home directory.groupadd
: Add a new group.
groupadd groupname
.groupdel
: Delete a group.
groupdel groupname
.