GNU/Linux most wanted Displaying file contents Comparing 2 directories:
diff -r dir1 dir2
tar jcvf archive.tar.bz2 dir tar Jcvf archive.tar.xz dir Misc commands Concatenate and display file contents: tar --lzma -cvf archive.tar.lzma Basic command-line calculator Summary of most useful commands cat file1 file2 Looking for files bc -l Test (list) a compressed archive: Display the contents of several files (stopping Find all files in the current (.) directory and its Copyright 2017-2005, Free Electrons. at each page): tar tvf archive.tar.[gz|bz2|lzma|xz] Basic system administration Free to share under the terms of the Creative Commons subdirectories with log in their name: Attribution-ShareAlike 3.0 license more file1 file2 find . -name *log* Extract the contents of a compressed archive: Change the owner and group of a directory and (http://creativecommons.org) less file1 file2 (better: extra features) tar xvf archive.tar.[gz|bz2|lzma|xz] all its contents: Find all the .pdf files in dir and subdirectories sudo chown -R newuser.newgroup dir Electronic version, sources, translations and updates: Display the first 10 lines of a file: and run a command on each: tar options: http://free-electrons.com/doc/legacy/command-line/ head -10 file c: create Reboot the machine in 5 minutes: find . -name *.pdf -exec xpdf {} ';' t: test sudo shutdown -r +5 Thanks to Michel Blanc, Hermann J. Beckers and Thierry Display the last 10 lines of a file: Grellier. Quick system-wide file search by pattern x: extract tail -10 file (caution: index based, misses new files): Shutdown the machine now: j: on the fly bzip2 (un)compression sudo shutdown -h now Latest update: Feb 8, 2017 locate *pub* J: on the fly xz (un)compression File name pattern matching z: on the fly gzip (un)compression Display all available network interfaces: Handling files and directories Concatenate all regular files: Redirecting command output ifconfig -a cat * Handling zip archives Create a directory: Redirect command output to a file: Assign an IP address to a network interface: zip -r archive.zip <files> (create) mkdir dir Concatenate all hidden files: ls *.png > image_files sudo ifconfig eth0 207.46.130.108 unzip -t archive.zip (test / list) Create nested directories: cat .* Append command output to an existing file: unzip archive.zip (extract) Bring down a network interface: mkdir -p dir1/dir2 Concatenate all files ending with .log: ls *.jpg >> image_files sudo ifconfig eth0 down cat *.log Redirect command output to the input of Printing Changing directories: Define a default gateway for packets to cd newdir List regular files with bug in their name: another command: Send PostScript or text files to queue: machines outside the local network: cd .. (parent directory) cat *.log | grep error lpr -Pqueue f1.ps f2.txt (local printer) sudo route add default gw 192.168.0.1 ls *bug* cd - (previous directory) List all regular files ending with . and a Job control List all the print jobs in queue: Delete the default route: cd (home directory) single character: lpq -Pqueue sudo route del default cd ~bill (home directory of user bill) Show all running processes: ls *.? Cancel a print job number in queue: Print the working (current) directory: ps -ef Test networking with another machine: cancel 123 queue ping 207.46.130.108 pwd Handling file contents Live hit-parade of processes (press P, M, T: sort by Processor, Memory or Time usage): Print a PDF file: Create or remove partitions on the first IDE Copy a file to another: Show only the lines in a file containing a given top pdf2ps doc.pdf hard disk: cp source_file dest_file substring: lpr doc.ps fdisk /dev/hda1 grep substring file Send a termination signal to a process: Copy files to a directory: cp file1 file2 dir kill <pid> (number found in ps output) View a PostScript file: Create (format) an ext3 filesystem: Case insensitive search: ps2pdf doc.ps mkfs.ext3 /dev/hda1 grep -i substring file Have the kernel kill a process: xpdf doc.pdf Copy directories recursively: cp -r source_dir dest_dir kill -9 <pid> Create (format) a FAT32 filesystem: Showing all the lines but the ones containing a mkfs.vfat -v -F 32 /dev/hda2 rsync -a source_dir/ dest_dir/ substring: Kill all processes (at least all user ones): User management grep -v substring file kill -9 -1 List users logged on the system: Mount a formatted partition: Create a symbolic link: ln -s linked_file link who mkdir /mnt/usbdisk (just do it once) Search through all the files in a directory: Kill a graphical application: sudo mount /dev/uba1 /mnt/usbdisk grep -r substring dir xkill (click on the program window to kill) Show which user I am logged as: Rename a file, link or directory: mv source_file dest_file whoami Mount a filesystem image (loop device): Sort lines in a given file: sort file File and partition sizes Show which groups user belongs to: sudo mount -o loop fs.img /mnt/fs Remove files or links: rm file1 file2 Show the total size on disk of files or groups user Unmount a filesystem: Sort lines, only display duplicate ones once: directories (disk usage): sudo umount /mnt/usbdisk sort -u file (unique) Tell more information about user: Remove empty directories: du -sh dir1 dir2 file1 file2 rmdir dir finger user Check the system kernel version: Changing file access rights Number of bytes, words and lines in file: uname -a Remove non-empty directories: wc file (word count) Switch to user hulk: rm -rf dir Add write permissions to the current user: su - hulk chmod u+w file Show the size, total space and free space of the Switch to super user (root): Listing files Add read permissions to users in the file group: current partition: su - (switch user) chmod g+r file df -h . List all regular files (not starting with .) in su (keep same directory and environment) the current directory: Add execute permissions to other users: Display these info for all partitions: ls chmod o+x file df -h Time management Display a long listing: Add read + write permissions to all users: Compressing Wait for 60 seconds: ls -l chmod a+rw file sleep 60 Compress a file: List all the files in the current directory, Make executable files executable by all: gzip file (.gz format) Show the current date: including hidden ones (starting with .): chmod a+rX * bzip2 file (.bz2 format, better) date ls -a lzma file (.lzma format, best compression) Make the whole directory and its contents Count the time taken by a command: List by time (most recent files first): accessible by all users: xz file (.xz format, best for code) time find_charming_prince -cute -rich ls -t chmod -R a+rX dir (recursive) Uncompress a file: List by size (biggest files first) gunzip file.gz Command help ls -S Comparing files and directories bunzip2 file.bz2 Basic help (works for most commands): unlzma file.lzma grep --help Comparing 2 files: List with a reverse sort order: unxz file.xz diff file1 file2 ls -r Access the full manual page of a command: Long list with most recent files last: Comparing 2 files (graphical): Archiving man grep gvimdiff file1 file2 ls -ltr Create a compressed archive (tape archive): tkdiff file1 file2 meld file1 file2 tar zcvf archive.tar.gz dir