Quick viewing(Text Mode)

Linux Basic Commands

Linux Basic Commands

Display the contents of several files (stopping Comparing 2 directories: Archiving Time management each page): -r dir1 dir2 Create a compressed archive (tape archive): for 60 seconds: file1 file2 zcvf archive.tar.gz / 60 file1 file2 (better: extra features) Looking for files tar jcvf archive.tar.bz2 dir/ (better) all files in the current (.) and its Show the current date: Display the first 10 lines of a : subdirectories with log in their name: (list) a compressed archive: date -10 file find . -name “*log*” tar ztvf archive.tar.gz tar jtvf archive.tar.bz2 Count the taken by a command: Basic Commands Display the last 10 lines of a file: Find all the .pdf files in dir and subdirectories time find_charming_prince -cute -rich -10 file and run a command on each: Extract the contents of a compressed archive: Handling files and directories find . -name “*.pdf” -exec xpdf {} ';' tar zxvf archive.tar.gz Command Create a directory: File name pattern matching tar jxvf archive.tar.bz2 Basic help (works for commands): dir Concatenate all “regular” files: Quick system-wide file search by pattern –help * (caution: index based, misses new files): tar options: Create nested directories: Concatenate all “hidden” files: “*pub*” c: create Access the full manual page of a command: mkdir -p dir1/dir2 cat .* t: test man grep Concatenate all files ending with .log: Redirecting command output x: extract Changing directories: cat *.log Redirect command output to a file: j: on the fly (un)compression Misc commands newdir List “regular” files with bug in their name: *.png > image_files z: on the fly (un)compression Basic command-line calculator cd .. (parent directory) ls *bug* bc -l cd - (previous directory) List all “regular” files ending with . and a Append command output to an existing file: Using 7-: (better compression than bzip2!) cd (home directory) single character: ls *.jpg >> image_files a archive.7z (add: create) Basic system administration cd ~bill (home directory of user bill) ls *.? 7z l archive.7z (list) Change the owner and group of a directory and Redirect command output to the input of another 7z x archive.7z (extract) all its contents: Print the working (current) directory: Handling file contents command: -R newuser:newgroup dir Show only the lines in a file containing a given cat *.log | grep error 7-zip compressed tar archive substring: (keeps user and group information) Reboot the machine in 5 minutes: a file to another: grep substring file tar cf dir | 7z a si dir.tar.7z (create) -r +5 source_file dest_file Show all running processes: 7z x so dir.tar.7z | tar xf (extract) Case insensitive search: -ef Shutdown the machine now: Copy files to a directory: grep -i substring file Handling zip archives shutdown -h now cp file1 file2 dir Live hit-parade of processes (press P, M, T: zip -r archive.zip (create) Showing all the lines but the ones containing by Processor, Memory or Time usage): unzip -t archive.zip (test / list) Display all available network interfaces: Copy directories recursively: a substring: unzip archive.zip (extract) -a cp -r source_dir dest_dir grep - substring file rsync -a source_dir/ dest_dir/ Send a termination to a : Printing Assign an IP address to a network interface: Search through all the files in a directory: (number found in ps output) Send PostScript or text files to queue: ifconfig eth0 207.46.130.108 Create a symbolic : grep -r substring dir lpr -Pqueue f1.ps f2.txt (local printer) -s linked_file link Have the kernel kill a process: Bring down a network interface: Sort lines in a given file: kill -9 List all the jobs in queue: ifconfig eth0 down Rename a file, link or directory: sort file lpq -Pqueue source_file dest_file Kill all processes (at least all user ones): Define a default gateway for packets to Sort lines, only display duplicate ones once: kill -9 -l Cancel a print job number in queue: machines outside the local network: Remove files or links: sort -u file (unique) cancel 123 queue add default gw 192.168.0.1 file1 file2 Kill a graphical application: Changing file access rights xkill (click on the program window to kill) Print a PDF file: Delete the default route: Remove empty directories: Add permissions to the current user: pdf2ps doc.pdf route default dir u+ file File and partition sizes lpr doc.ps Show the total size on disk of files or directories Test networking with another machine: Remove non-empty directories: Add read permissions to users in the file group: (disk usage): View a PostScript file: ping 207.46.130.108 rm -rf dir chmod g+r file -sh dir1 dir2 file1 file2 ps2pdf doc.ps xpdf doc.pdf Create or remove partitions on the first IDE Listing files Add execute permissions to other users: Number of , words and lines in file: hard disk: List all “regular” files (not starting with .) in chmod o+x file file (word count) User management /dev/hda1 the current directory: List users logged on the system: ls Add read + write permissions to all users: Show the size, total space and free space of the Create () an ext3 filesystem: Display a long listing: chmod a+rw file current partition: .ext3 /dev/hda1 ls -l -h . Show user I am logged as: List all the files in the current directory, executable files executable by all: Create (format) a FAT32 filesystem: including “hidden” ones (starting with .):chmod a+rX * Display these for all partitions: mkfs.vfat -v -F 32 /dev/hda2 ls -a df -h Show which groups user belongs to: List by time (most recent files first): Make the whole directory and its contents groups user a formatted partition: ls -t accessible by all users: Compressing mkdir /mnt/usbdisk (just do it once) List by size (biggest files first) chmod -R a+rX dir (recursive) a file: Tell more information about user: mount /dev/uba1 /mnt/usbdisk ls -S gzip file (.gz format) finger user List with a reverse sort order: Comparing files and directories bzip2 file (.bz2 format, better) Mount a filesystem image (loop device): ls -r Comparing 2 files: Switch to user hulk: mount -o loop initrd.img /mnt/initrd Long list with most recent files last: diff file1 file2 Uncompress a file: hulk ls -ltr gunzip file.gz Unmount a filesystem: Comparing 2 files (graphical): bunzip2 file.bz2 Switch to super user (root): umount /mnt/usbdisk Displaying file contents gvimdiff file1 file2 su (switch user) Concatenate and display file contents: tkdiff file1 file2 su (keep same directory and environment) Check the system kernel version: cat file1 file2 kompare file1 file2 -a so-logic Lustkandlgasse 52/22 A-1090 Vienna,Austria/Europe; Phone: +43-1-315 77 77-11 SO-REFERENCE CARD www.so-logic. so_babel_20080728 - linux basic commands