Linux Commands
File Commands:
ls: List directory contents.ls -al: Formatted listing with hidden files.cd dir: Change directory to dir.cd: Change to home directory.pwd: Show current directory.mkdir dir: Create a directory named dir.rm file: Delete a file.rm -r dir: Delete a directory (recursively).rm -f file: Force remove a file.rm -rf dir: Force remove a directory (be cautious with this command).cp file1 file2: Copy file1 to file2.cp -r dir1 dir2: Copy dir1 to dir2; create dir2 if it doesn't exist.mv file1 file2: Rename or move file1 to file2. If file2 is an existing directory, moves file1 into directory file2.ln -s file link: Create a symbolic link (shortcut) named link to file.touch file: Create or update a file.cat > file: Place standard input into file.more file: Output the contents of a file.head file: Output the first 10 lines of a file.tail file: Output the last 10 lines of a file.tail -f file: Output the contents of a file as it grows, starting with the last 10 lines.
Process Management:
ps: Display your currently active processes.top: Display all running processes.kill pid: Kill a process with process ID pid.killall proc: Kill all processes with the name proc.bg: List stopped or background jobs; resume a stopped job in the background.fg: Bring the most recent job to the foreground.fg n: Bring job n to the foreground.
File Permissions:
chmod octal file: Change the permissions of a file to octal (numeric representation), specifying read (4), write (2), and execute (1) permissions for user, group, and world.- Examples:
chmod 777 file: Read, write, and execute for all.chmod 755 file: Rwx for owner, rx for group and world.
- Examples:
SSH:
ssh user@host: Connect to a host as a user.ssh -p port user@host: Connect to a host on a specific port as a user.ssh-copy-id user@host: Add your SSH key to a host for a user to enable a passwordless login.
Searching:
grep pattern files: Search for a pattern in files.grep -r pattern dir: Search recursively for a pattern in a directory.command | grep pattern: Search for a pattern in the output of a command.locate file: Find all instances of a file.
System Info:
date: Show the current date and time.cal: Show this month's calendar.uptime: Show current uptime.w: Display who is online.whoami: Display the currently logged-in user.finger user: Display information about a user.uname -a: Show kernel information.cat /proc/cpuinfo: Display CPU information.cat /proc/meminfo: Display memory information.man command: Show the manual for a command.df: Show disk usage.du: Show directory space usage.free: Show memory and swap usage.whereis app: Show possible locations of an app.which app: Show which app will be run by default.
Compression:
tar cf file.tar files: Create a tar file named file.tar containing specified files.tar xf file.tar: Extract the files from a tar file.tar czf file.tar.gz files: Create a tar file with Gzip compression.tar xzf file.tar.gz: Extract a tar file using Gzip.tar cjf file.tar.bz2: Create a tar file with Bzip2 compression.tar xjf file.tar.bz2: Extract a tar file using Bzip2.gzip file: Compress a file and rename it to file.gz.gzip -d file.gz: Decompress a file.gz back to the original file.
Network:
ping host: Ping a host and output results.whois domain: Get whois information for a domain.dig domain: Get DNS information for a domain.dig -x host: Reverse lookup for a host.wget file: Download a file.wget -c file: Continue a stopped download.
Installation:
dpkg -i pkg.deb: Install a Debian package.rpm -Uvh pkg.rpm: Install an RPM package.
Install from Source:
./configuremakemake install
Shortcuts:
Ctrl+C: Halt the current command.Ctrl+Z: Stop the current command; resume withfgin the foreground orbgin the background.Ctrl+D: Log out of the current session (similar toexit).Ctrl+W: Erase one word in the current line.Ctrl+U: Erase the whole line.Ctrl+R: Type to bring up a recent command.!!: Repeat the last command.exit: Log out of the current session.