0% found this document useful (0 votes)
26 views1 page

Command Memento

The document provides a comprehensive list of useful GNU/Linux commands for various tasks including file management, system administration, and networking. It includes commands for creating directories, comparing files, archiving, and managing user permissions, along with examples for each command. Additionally, it offers tips for file searching, printing, and time management commands.

Uploaded by

jeremias
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
26 views1 page

Command Memento

The document provides a comprehensive list of useful GNU/Linux commands for various tasks including file management, system administration, and networking. It includes commands for creating directories, comparing files, archiving, and managing user permissions, along with examples for each command. Additionally, it offers tips for file searching, printing, and time management commands.

Uploaded by

jeremias
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

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

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

You might also like