Basic knowledge
Summary of 600 Strongest Linux Commands
1. Basic commands
Uname - m displays the processor architecture of the machine
Uname - r displays the kernel version being used
Dmide code - q display hardware system components
(SMBIOS/DMI) hdparm - i/dev/hda List the architectural characteristics of a disk
Hdparm - tT/dev/sda performs testable read of operating system information on disk
Arch displays the processor architecture of the machine
Uname - m displays the processor architecture of the machine
Uname - r displays the kernel version being used
Dmidecode - q Display Hardware System Components - (SMBIOS/DMI)
Hdparm - i/dev/hda List the architectural features of a disk
Hdparm - tT/dev/sda performs testable read operations on disk
Cat/proc/cpuinfo displays CPU information
Cat/proc/interrupts display interrupts
Cat/proc/meminfo Verify Memory Usage
Cat/proc/swaps displays which swaps are being used
Cat/proc/version displays the version of the kernel
Cat/proc/net/dev displays network adapters and statistics
Cat/proc/mounts displays loaded file systems
Lspci - tv List PCI Devices
LsUSB - TV Display USB Device
Date displays the system date
Cal 2007 displays the calendar for 2007
Date 041217002007.00 Set date and time - month, day, hour, year, second
Clock - w Save time modifications to BIOS
2. Shutdown
Shutdown - h now Shut down the system (1)
Init 0 Shutdown System (2)
Telinit 0 shuts down the system (3)
Shutdown - h hours: minutes&shut down the system at the scheduled time
Shutdown - c Cancel shutting down the system at the scheduled time
Shutdown - r now restart (1)
Reboot (2)
Logout logout
3. Files and directories
CD/home Enter the '/home' directory
cd .. Return to the previous level directory
cd ../.. Return to the upper two levels of directory
CD enters personal home directory
Cd~user1 enters the personal home directory
Cd - returns the directory where it was last located
Pwd displays the working path
Ls View files in the directory
Ls - F View files in directory
Ls - l displays detailed information about files and directories
Ls - a Show Hidden Files
Ls * [0-9] * Display file and directory names containing numbers
Tree displays the tree structure of files and directories starting from the root directory (1)
Lstree displays the tree structure of files and directories starting from the root directory (2)
Mkdir dir1 creates a directory called 'dir1'
Mkdir dir1 dir2 Create two directories simultaneously
Mkdir - p/tmp/dir1/dir2 Create a directory tree
Rm - f file1 Delete a file called 'file1'
Rmdir dir1 deletes a directory called 'dir1'
Rm - rf dir1 deletes a directory called 'dir1' and simultaneously deletes its contents
Rm - rf dir1 dir2 delete both directories and their contents simultaneously
mv dir1 new_ Dir renaming/moving a directory
Cp file1 file2 copying a file
cp dir/* . Copy all files in a directory to the current working directory
cp -a /tmp/dir1 . Copy a directory to the current working directory
Cp - a dir1 dir2 Copy a directory
Ln - s file1 lnk1 Create a soft link to a file or directory
Ln file1 lnk1 Create a physical link to a file or directory
Touch - t 0712250000 file1 Modify the timestamp of a file or directory - (YYMMDDhhmm)
file file1 outputs the mime type of the file as text
Iconv - l List known encodings
iconv -f fromEncoding -t toEncoding inputFile > outputFile creates a new from the given input file by assuming it is encoded in fromEncoding and converting it to toEncoding.
find . - maxdepth 1 -name *.jpg -print -exec convert "{}" -resize 80x60 "thumbs/{}" \; batch resize files in the current directory and send them to a thumbnails directory (requires convert from Imagemagick)
4. File Search
Find/- name file1 starts from '/' and enters the root file system to search for files and directories
Find/- user user1 searches for files and directories belonging to user 'user1'
Find/home/user1- name *. bin Search for files with a '. bin' ending in directory '/home/user1'
Find/usr/bin - type f - time+100 Search for executable files that have not been used in the past 100 days
Find/usr/bin - type f - mtime -10 Search for files created or modified within 10 days
find / -name \*.rpm -exec chmod 755 '{}' \; Search for files ending in '. rpm' and define their permissions
Find/- xdev name *. rpm Search for files ending in '. rpm', ignoring removable devices such as optical drives and flash drives
Locate *. ps Find files ending in '. ps' - run the' updatedb 'command first
Where is halt displays the location of a binary file, source code, or man
Which halt displays the full path of a binary or executable file
5. Mount a file system
Mount/dev/hda2/mnt/hda2 Mount a disk called hda2- make sure the directory '/mnt/hda2' already exists
Umount/dev/hda2 uninstalls a disk called hda2- first exit from the mount point '/mnt/hda2'
Fuser - km/mnt/hda2 Force uninstallation when device is busy
Umount - n/mnt/hda2 Runs an uninstall operation without writing to the/etc/mtab file - useful when the file is read-only or when the disk is full
Mount/dev/fd0/mnt/floppy to mount a floppy disk
Mount/dev/cdrom/mnt/cdrom Mount a cdrom or dvdrom
Mount/dev/hdc/mnt/cdrecord Mount a cdrw or dvdrom
Mount/dev/hdb/mnt/cdrecord Mount a cdrw or dvdrom
Mount - o loop file.iso/mnt/cdrom Mount a file or ISO image file
Mount - t vfat/dev/hda5/mnt/hda5 Mount a Windows FAT32 file system
Mount/dev/sda1/mnt/usbdisk Mount a USB flash drive or flash device
Mount - t smbfs - o username=user, password=pass//WinClient/share/mnt/share Mount a Windows network share
6. Disk space
Df - h displays a list of mounted partitions
Ls - lSr | more Arrange files and directories by size
Du - sh dir1 estimates the disk space already used by directory 'dir1'
Du sk * | sort rn displays the size of files and directories in order based on capacity size
Rpm - q - a -- qf '% 10 {SIZE} t% {NAME}n' | sort - k1,1n Display the space used by installed rpm packages in order of size (Fedora, Redhat class systems)
Dpkg query W - f='{Installed Size; 10}t ${Package}n' | sort - k1,1n Display the space used by installed deb packages based on size (ubuntu, Debian class system)
7. Users and Groups
groupadd group_ Name creates a new user group
groupdel group_ Name deletes a user group
groupmod -n new_ group_ name old_ group_ Name renames a user group
Useradd - c "Name Surname" - g admin - d/home/user1- s/bin/bash user1 Create a user belonging to the "admin" user group
Useradd user1 creates a new user
Userdel - r user1 delete a user ('- r' exclude home directory)
Usermod - c "User FTP" - g system - d/ftp/user1- s/bin/nologin user1 Modify user attributes
Passwd Change Password
Passwd user1 modifies the password of a user (only root is allowed to execute)
Chage E 2005-12-31 user1 sets the expiration date for user passwords
Pwck checks for file format and syntax corrections for '/etc/passwd', as well as the presence of users
Grpck checks file format and syntax corrections for '/etc/passwd', as well as existing groups
newgrp group_ Name logs in to a new group to change the default group for newly created files
8. File permissions, use "+" to set permissions, use "-" to cancel
Ls - lh Display Permissions
Ls/tmp | pr - T5- W $COLUMNS divides the terminal into 5 columns for display
Chmod ugo+rwx directory1 Set permissions for everyone (u), group (g), and others (o) in the directory to read (r), write (w), and execute (x)
Chmod go rwx directory1 Delete group (g) and others (o) Read and write permissions to the directory
Chown user1 file1 changes the owner attribute of a file
Chown - R user1 directory1 changes the owner attributes of a directory and simultaneously changes the attributes of all files in the directory
Chgrp group1 file1 changes the group of files
Chown user1: group1 file1 Changes the owner and group attributes of a file
Find/- perm - u+s List all files in a system that use SUID control
Chmod u+s/bin/file1 sets the SUID bit of a binary file - the user running the file is also granted the same permissions as the owner
Chmod u-s/bin/file1 disable the SUID bit of a binary file
Chmod g+s/home/public sets the SGID bit of a directory - similar to SUID, but this is specific to the directory
Chmod g-s/home/public disable the SGID bit of a directory
Chmod o+t/home/public Set the STIKY bit of a file - only legal owners are allowed to delete files
Chmod o-t/home/public disable the STIKY bit of a directory
Chmod+x file path adds execution permissions for the owner, group, and other users
The chmod - x file path contains the permissions for the owner, group, and other users to delete and execute
Chmod u+x file path adds execution permissions for the owner
Chmod g+x file path adds execution permissions for the group to which it belongs
Chmod o+x file path adds execution permissions for other users
chmo