GNU/Linux Most Wanted: Summary of Most Useful Commands

Download as pdf or txt
Download as pdf or txt
You are on page 1of 1

GNU/Linux most wanted Long list with most recent files last:

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

You might also like