Info: ----- pwd [print working directory] date [sho current date and time] cal [calendar] cat /proc/cpuinfo [cpu info] cat /proc/cpuinfo | grep processor | wc -l [No. of cpus] cat /proc/cpuinfo | grep 'core id' [No. of cores] cat /proc/meminfo [memory info] free -h [memory usage info] uptime [show up time] uname -a [show system and kernel] cat /etc/issue [or head -n1 /etc/issue] [show distro] who [Show who is logged into the system] whoami [show your username] whereis ls (any cmd) [or which ls] df -Th [show disk usage] du [show directory space usage] [du -Sh | sort -rh | head -n 15] or [du -s * | sort -n | cut -f2 | xargs -d "\n" du -sh] last reboot [Show system reboot history] hostname [Show system host name] hostname -I [Display the IP addresses of the host] lspci -tv [Display PCI devices] lsusb -tv [Display USB devices] lshw [Displays information about system’s hardware configuration] lsblk [Displays block devices related information] hdparm -i /dev/sda [Show info about disk sda, needs root access] fdisk -l [Display disks partitions sizes and types, needs root access] dmidecode [Displays hardware information from the BIOS] Enviroment Variables: --------------------- env [show enviroment variables] echo $HOME [home directory path] echo $PATH [bin paths] echo $SHELL [shell bin file path] export NAME=value [Set $NAME to value] Multiple Commands: ------------------ cmd1 | cmd2 [pipes] cmd1 ; cmd2 [Run cmd1 then cmd2] cmd1 && cmd2 [Run cmd2 if cmd1 is successful] cmd1 || cmd2 [Run cmd2 if cmd1 is not successful] File and Directory: ------------------- pwd [print working directory] mkdir dir1 [create a directory called 'dir1'] rmdir dir [remove dir1, if it's empty] ls [list files and folders] cd dir1 [change to dir1] cd ~ [change to user's home directory] cd .. [change to parent directory] rm -rf dir1 [remove dir1 recursivly and forcably] touch file1 [create file1] cat file1 [show file1 content] less file1 [View and paginate file1] file file1 [Get file1 type] cp file1 file2 [Copy file1 to file2] cp -r dir1 dir2 [Recursively Copies dir1 to dir2. dir2 is created if it does not exist] mv file1 file2 [Move/Rename file1 to file2] rm file1 [Delete file1] head file1 [Show first 10 lines of file1, , -n: number of lines] tail file1 [Show last 10 lines of file1, -n: number of lines] stat file [file info] stat -c "%a %n" * [list by permission numerical mode] ln -s file1 link1 [create symbolic link link1 to file1] sort file1 (sort the content of file1 alphabetically, r: reverse, n: numbers) sort -o file1 file2 (sort the content of file1 alphabetically and write the result to a file2) wc file1 [count number of words in file1, nbr of line, nbr of words, byte size, -l (lines), -w (words), -c (byte size), -m (number of characters)] ls Parameters: -------------- -a Show all (including hidden) -R Recursive list -r Reverse order -t Sort by last modified -S Sort by file size -l Long listing format -1 One file per line -m Comma-separated output -Q Quoted output -h Human Readable -s Size Search: ------- grep Doc *txt [search inside text files for 'Doc'][-i: case insensitive, -r: recursive] find /dir/ -name name* [Find files starting with name in dir] find /dir -user name [Find files owned by name in dir] find /dir -size +100M [Find files larger than 100MB in /dir] locate file [Find file (quick search of system index)] nano: ----- CTRL+0: save CTRL+X: exit CTRL+C: show line number CTRL+SHIFT+-: goto line number # CTRL+W: find ALT+W: find next CTRL+\: replace Permissions: ------------ 4 read (r) 2 write (w) 1 execute (x) chmod 775 file [Change mode of file to 775, -r: recursive] chown user:group file chmod u+rwx,g+rw,o+r file chmod a+rwx file [u]: user [g]: group [o]: other User: ----- id [Display the user and group ids of your current user] last [Display the last users who have logged onto the system] who [Show who is logged into the system] w [Show who is logged in and what they are doing] adduser user1 [create a user named 'user1'] passwd user1 [change user1 password] deluser [delete user1] userdel [delete user1] addgroup group1 [create a new group named group1] delgroup group1 [delete group1] usermod -g group1 use1 [add user1 to group1] usermod -g user1 user1_new_name [change account name] usermod -aG group1 user1 [add groups to a user with-out loosing the ones he's already in] Network: -------- ping host [ping host and output results] whois domain [get whois information for domain] dig domain [get DNS information for domain] dig -x host [reverse lookup host] wget file [download file] wget -c file [continue a stopped download] wget --user user --password pass http://example.com/ [authorized] hostname [Show system host name] hostname -I [Display the IP addresses of the host] hostname -i [Display the network address of the host name] netstat -nutlp [Display listening tcp and udp ports and corresponding programs] ip addr show [Displays IP addresses and all the network interfaces] ip address add 192.168.0.1/24 dev eth0 [Assigns IP address 192.168.0.1 to interface eth0] Compression: ------------ tar cf dir1.tar dir1 [create a tar named dir1.tar containing dir1] tar xf dir1.tar [extract dir1 from dir1.tar] tar czf dir1.tar.gz dir1 [create a tar with Gzip compression] tar xzf dir1.tar.gz [extract a tar using Gzip] tar cjf file.tar.bz2 [create a tar with Bzip2 compression] tar xjf file.tar.bz2 [extract a tar using Bzip2] gzip dir1 [compresses dir1 and renames it to dir1.gz] gzip -d dir1.gz [decompresses dir1.gz back to dir1] zip -r dir1 dir1.zip unzip dir1.zip Processes & Monitoring: ----------------------- ps [display your currently active processes] top (or ps -ef) [display all running processes] kill pid [kill process id pid] kill -9 pid [violent kill] killall proc1 [kill all processes named proc1] program & [Start program in the background] bg [lists stopped or background jobs; resume a stopped job in the background] fg [brings the most recent job to foreground] fg n [brings job n to the foreground] pstree -paul [Visualizing processes in tree model] pgrep firefox [Find Firefox process ID] Monitoring Tools: ----------------- ps [display your currently active processes] top [display all running processes] htop, glances mpstat 1 [Display processor related statistics] vmstat 1 [Display virtual memory statistics] iostat 1 [Display I/O statistics] tail -n 100 /var/log/syslog free -h [memory usage info] df -Th [show disk usage] du [show directory space usage] watch df -Th [Execute "df -Th", showing periodic updates, very useful] tcpdump -i eth0 [Capture and display all packets on interface eth0] tcpdump -i eth0 'port 80' [Monitor all traffic on port 80 ( HTTP )] lsof [List all open files on the system] lsof -u user1 [List files opened by user1] pstree [Visualizing processes in tree model] tload [graphic representation of system load average] iftop [Displays Bandwidth Usage] nload [Displays Network Usage] IPTraf [An IP Network Monitor] File Transfer: -------------- scp file.txt user1@server1:/tmp [Secure copy file.txt to the /tmp folder on server1] scp user1@server1:/var/www/*.html /tmp [Copy *.html files from server1 to the local /tmp folder] scp -r server1:/var/www /tmp [Copy all files and directories recursively from server1 to the current system's /tmp folder] rsync -a /home /backups/ [Synchronize /home to /backups/home] rsync -avz /home user1@server1:/backups/ [Synchronize files/directories between the local and remote system with compression enabled] Misc: ----- screen [running commands in sessions (even when you logout from ssh)] ctrl+A followed by 'd' to exit: screen -r to restore session, screen -ls to show all sessions, screen -r id, to restore to a specific session. history [display a history of your commands] hault or poweroff [shutdown the computer] reboot [reboot the computer] clear [clear the terminal screen] exit [exit terminal]
CentOS, General, Manjaro, Ubuntu
I see this very handy mate, thanks for sharing it 🙂
Glad you found it useful 😉