Displaying contents Comparing 2 directories: tar jcvf archive.tar.bz2 dir Misc commands GNU/Linux most wanted -r dir1 dir2 tar Jcvf archive.tar.xz dir Concatenate and display file contents: tar --lzma -cvf archive.tar.lzma Basic command-line calculator Summary of most useful commands file1 file2 Looking for files bc -l (list) a compressed archive: ©Copyright 2017-2005, Free Electrons. Display the contents of several files (stopping all files in the current (.) directory and its tar tvf archive.tar.[gz|bz2|lzma|xz] Basic system administration Free to share under the terms of the Creative Commons each page): subdirectories with log in their name: Attribution-ShareAlike 3.0 license file1 file2 find . -name “*log*” Extract the contents of a compressed archive: Change the owner and group of a directory and (http://creativecommons.org) 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 -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/ -10 file find . -name “*.pdf” -exec xpdf {} ';' c: create Reboot the machine in 5 minutes: 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 -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*” File name pattern matching J: on the fly xz (un)compression 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 Handling zip archives Create a directory: cat * Redirect command output to a file: zip -r archive.zip (create) Assign an IP address to a network interface: dir *.png > image_files Concatenate all “hidden” files: unzip -t archive.zip (test / list) sudo ifconfig eth0 207.46.130.108 cat .* Create nested directories: 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 Printing Changing directories: Redirect command output to the input of Define a default gateway for packets to Send PostScript or text files to : newdir List “regular” files with bug in their name: another command: queue machines outside the local network: cd .. (parent directory) ls *bug* cat *.log | error lpr -Pqueue f1. f2.txt (local printer) sudo route add default gw 192.168.0.1 cd - (previous directory) List all the print jobs in queue: cd (home directory) List all “regular” files ending with . and a Delete the default route: 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 Handling file contents Live hit-parade of processes (press P, M, T: 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 by Processor, Memory or usage): pdf2ps doc.pdf hard disk: source_file dest_file substring: top lpr doc.ps fdisk /dev/hda1 grep substring file Copy files to a directory: Send a termination signal to a process: View a PostScript file: Create (format) an ext3 filesystem: cp file1 file2 dir Case insensitive search: (number found in ps output) ps2pdf doc.ps mkfs.ext3 /dev/hda1 grep -i substring file Copy directories recursively: Have the kernel kill a process: xpdf doc.pdf Create (format) a FAT32 filesystem: cp -r source_dir dest_dir Showing all the lines but the ones containing a kill -9 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 Create a symbolic link: kill -9 -1 List users logged on the system: Mount a formatted partition: mkdir /mnt/usbdisk (just do it once) -s linked_file link Search through all the files in a directory: Kill a graphical application: sudo mount /dev/uba1 /mnt/usbdisk grep -r substring dir Rename a file, link or directory: xkill (click on the program window to kill) Show which user I am logged as: Mount a filesystem image (loop device): source_file dest_file Sort lines in a given file: whoami sudo mount -o loop fs.img /mnt/fs sort file File and partition sizes Remove files or links: Show which groups user belongs to: Unmount a filesystem: file1 file2 Sort lines, only display duplicate ones once: Show the total size on disk of files or groups user sudo umount /mnt/usbdisk sort -u file (unique) directories (disk usage): Remove empty directories: -sh dir1 dir2 file1 file2 Tell more information about user: dir finger user Check the system kernel version: Changing file access rights Number of bytes, words and lines in file: -a Remove non-empty directories: Switch to user hulk: Add permissions to the current user: file (word count) rm -rf dir su - hulk 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 -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 for 60 seconds: ls -l chmod a+rw file 60 Compress a file: List all the files in the current directory, 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 ( format, best compression) Make the whole directory and its contents lzma file .lzma 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): Comparing 2 files: unlzma file.lzma grep --help List with a reverse sort order: diff file1 file2 unxz file.xz ls -r Access the full manual page of a command: Comparing 2 files (graphical): man grep Long list with most recent files last: Archiving gvimdiff file1 file2 ls -ltr tkdiff file1 file2 Create a compressed archive (tape archive): meld file1 file2 tar zcvf archive.tar.gz dir