Switch to linux common commands

System info
arch Show the processor architecture of the machine (1)
uname -m Show the processor architecture of the machine (2)
uname -r Show the kernel version in use
dmidecode -q Show hardware system components - (SMBIOS / DMI)
hdparm -i / dev/hda List the architectural features of a disk
hdparm -tT /dev/sda Perform a test read operation on the disk
cat /proc/cpuinfo Display CPU info information
cat /proc/interrupts Display interrupts
cat /proc/meminfo Verify memory Use
cat /proc/swaps to show which swaps are used
cat /proc/version to show kernel version
cat /proc/net/dev to show network adapters and statistics
cat /proc/mounts to show mounted filesystems
lspci -tv to list PCI devices
lsusb -tv Display USB device
date Display system date
cal 2007 Display 2007 calendar
date 041217002007.00 Set date and time - month, day, hour, minute, year. second
clock -w Save time modification to BIOS



shutdown (system shutdown, restart and logout)
shutdown -h now shuts down the system (1)
init 0 shuts down the system (2)
telinit 0 shuts down the system (3)
shutdown -h hours:minutes & shuts down the system at the scheduled time
shutdown -c cancels the system shutdown at the scheduled time
shutdown -r now restarts (1)
reboot restarts (2)
logout logout



files and directories
cd /home go to '/home' directory '
cd .. go back to the previous directory
cd ../.. go back two levels up
cd go to the personal home directory
cd ~user1 go to the personal home directory
cd - go back to above
pwd show the working path
ls view the files in the directory ls
-F view the files in the directory
ls -l show the details of the files and directories
ls -a show the hidden files
ls *[0-9]* show the files containing numbers File and directory names
tree show the tree structure of files and directories starting from the root directory (1)
lstree show the tree structure of files and directories starting from the root directory (2)
mkdir dir1 Create a directory called 'dir1''
mkdir dir1 dir2 Create two directories at the same time
mkdir -p /tmp/dir1/dir2 creates a directory tree
rm -f file1 delete a file called 'file1'
rmdir dir1 delete a directory called 'dir1'
rm -rf dir1 delete a directory called 'dir1' and delete its contents
rm -rf dir1 dir2 delete both Directories and their contents
mv dir1 new_dir Rename/move a directory
cp file1 file2 Copy 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 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 change 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)



file search
find / -name file1 enter root file system starting from '/' search files and directories
find / -user user1 search files and directories belonging to user 'user1'
find /home/user1 -name \*.bin in directory '/ home/user1' search for files ending with '.bin'
find /usr/bin -type f -atime +100 search for executable files that have not been used in the last 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 with '.rpm' and define their permissions
find / -xdev -name \ *.rpm Search for files ending with '.rpm', ignore removable devices such as CD-ROM, USB, etc.
locate \*.ps Find files ending with '.ps' - run 'updatedb' first The command
whereis halt shows the location of a binary, source or man
which halt show the full path to a binary or executable



mount a filesystem
mount /dev/hda2 /mnt/hda2 mount a disk called hda2 - make sure the directory '/mnt/hda2' already exists
umount /dev/hda2 unmount a disk called hda2 - first exit
fuser from mount point '/mnt/hda2' -km /mnt/hda2 force unmount when device is busy
umount -n /mnt/hda2 run unmount operation without writing to /etc/mtab file - useful when the file is read-only or when the disk is full
mount /dev/fd0 /mnt/floppy mounts a floppy disk
mount /dev/cdrom /mnt/cdrom mounts a cdrom or dvdrom
mount /dev/hdc /mnt /cdrecorder mounts a cdrw or dvdrom
mount /dev/hdb /mnt/cdrecorder mounts a cdrw or dvdrom
mount -o loop file.iso /mnt/cdrom mounts a file or ISO image
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



disk space
df -h display mounted partition list
ls -lSr |more arrange files by size and directory
du -sh dir1 Estimate the disk space used by the directory 'dir1''
du -sk * | sort -rn Display the size of files and directories in order based on capacity
rpm -q -a --qf '%10{SIZE }t%{NAME}n' | sort -k1,1n Displays the space used by installed rpm packages in order based on size (fedora, redhat systems)
dpkg-query -W -f='${Installed-Size ;10}t${Package}n' | sort -k1,1n show space used by installed deb packages by size (ubuntu, debian-like systems)

return top index ^

users and groups
groupadd group_name create a new user group
groupdel group_name delete a user group
groupmod -n new_group_name old_group_name rename a user group
useradd -c "Name Surname " -g admin -d /home/user1 -s /bin/bash user1 create a user group belonging to the "admin" user group user
useradd user1 creates a new user
userdel -r user1 deletes a user ('-r' excludes home directory)
usermod -c "User FTP" -g system -d /ftp/user1 -s /bin/nologin user1 modifies user attributes
passwd modifies password
passwd user1 Change a user's password (only allow root to execute)
chage -E 2005-12-31 user1 Set the expiration period of the user's password
pwck Check '/etc/passwd' file format and syntax correction and existing user
grpck check' /etc/passwd' file format and syntax fixes and existing group
newgrp group_name Login into a new group to change the default group for newly created files

Back to top index ^

File permissions - use "+" to set permissions, Use "-" to cancel
ls -lh show permissions
ls /tmp | pr -T5 -W$COLUMNS divide the terminal into 5 columns show
chmod ugo+rwx directory1 set the owner (u), group (g) and Others (o) with read (r), write (w) and execute (x) permissions
chmod go-rwx directory1 delete group (g) and others (o) read and write execute permissions on the directory
chown user1 file1 change Owner property of a file
chown -R user1 directory1 Change the owner attribute of a directory and also change the attributes of all files in the directory
chgrp group1 file1 Change the group
of a file chown user1:group1 file1 Change the owner and group attributes of a file
find / -perm - u+s List all files controlled by SUID on a system
chmod u+s /bin/file1 Set the SUID bit of a binary file - the user running the file is also given the same permissions as the owner
chmod us /bin/file1 Disable the SUID bit of a binary
chmod g+s /home/public Set the SGID bit of a directory - like SUID, but this is for a directory
chmod gs /home/public Disable the SGID bit of a directory
chmod o+t /home/ public set the STIKY bit of a file - only allow the legal owner to delete the file
chmod ot /home/public disable the STIKY bit of a directory

back to top index ^

special attributes of a file - use "+" to set permissions, use "-" to cancel
chattr +a file1 only allows to read and write files in append mode
chattr +c file1 allows this file to be automatically compressed/decompressed by the kernel
chattr +d file1 This file will be ignored by the dump program during file system backups
chattr +i file1 Makes an immutable file that cannot be deleted, modified, renamed, or linked
chattr +s file1 Allows a file to be deleted safely
chattr +S file1 Once an application writes to the file, the system immediately Write the result of the modification to disk
chattr +u file1 If the file is deleted, the system will allow you to restore the deleted file later
lsattr Show special attributes

Return to top index ^

Pack and compress the file
bunzip2 file1.bz2 Unzip a file called 'file1 .bz2'
bzip2 file1 compresses a file called 'file1'
gunzip file1.gz decompresses a file called 'file1.gz'
gzip file1 compresses a file called 'file1'
gzip -9 file1 compresses
rar a file1 as much as possible. rar test_file creates a package called 'file1.rar'
rar a file1.rar file1 file2 dir1 compresses 'file1', 'file2' and the directory 'dir1' at the same time
rar x file1.rar decompresses rar package
unrar x file1.rar decompresses rar package
tar -cvf archive.tar file1 creates an uncompressed tarball
tar -cvf archive.tar file1 file2 dir1 create an archive containing 'file1', 'file2' and 'dir1'
tar -tf archive.tar show the contents of
a package tar -xvf archive.tar release a package
tar - xvf archive.tar -C /tmp Release the archive to the /tmp directory
tar -cvfj archive.tar.bz2 dir1 Create a bzip2 archive
tar -xvfj archive.tar.bz2 Extract a bzip2 archive
tar - cvfz archive.tar.gz dir1 Create a gzip archive
tar -xvfz archive.tar.gz Extract a gzip archive
zip file1.zip file1 Create a zip archive
zip -r file1.zip file1 file2 dir1 Compresses several files and directories into a zip archive at the same time
unzip file1.zip Unzips a zip archive

Return to top index^

RPM packages - (Fedora, Redhat and similar systems)
rpm -ivh package.rpm Install an rpm package
rpm -ivh --nodeeps package.rpm install an rpm package ignoring dependency warnings
rpm -U package.rpm update an rpm package without changing its configuration file
rpm -F package.rpm update a certain installed rpm package
rpm -e package_name.rpm delete an rpm package
rpm -qa show all installed rpm packages in the system
rpm -qa | grep httpd show all names containing "httpd" rpm package with the words
rpm -qi package_name Get special information about an installed package
rpm -qg "System Environment/Daemons" Display the rpm package of a component
rpm -ql package_name Display a list of files provided by an installed rpm package
rpm -qc package_name Display a list of configuration files provided by an installed rpm package
rpm -q package_name --whatrequires Display a list of dependencies with an rpm package
rpm -q package_name --whatprovides Display the volume of an rpm package
rpm -q package_name -- scripts Display scripts executed during installation/removal l
rpm -q package_name --changelog Display the modification history of an rpm package
rpm -qf /etc/httpd/conf/httpd.conf Confirm which rpm package provides the given file
rpm -qp package.rpm -l display a list of files provided by an rpm package that has not been installed
rpm --import /media/cdrom/RPM-GPG-KEY Import public key digital certificate
rpm --checksig package.rpm Verify the integrity of an rpm package
rpm -qa gpg-pubkey Verify the integrity of all installed rpm packages
rpm -V package_name Check file size, permission, type, owner, group, MD5 check and last modified time
rpm -Va Check all installed rpm packages on the system - be careful with
rpm -Vp package.rpm to verify that an rpm package has not install
rpm2cpio package.rpm | cpio --extract --make-directories *bin* run executable from an rpm package
rpm -ivh /usr/src/redhat/RPMS/`arch`/package.rpm install from an rpm source a built package
rpmbuild --rebuild package_name.src.rpm builds an rpm package from an rpm source

back to top index ^

YUM Package Upgrader - (Fedora, RedHat and similar systems)
yum install package_name Downloads and installs an rpm package
yum localinstall package_name.rpm will install an rpm package, using your own repositories to resolve all dependencies for you
yum update package_name.rpm update all installed rpm packages on the current system
yum update package_name update an rpm package
yum remove package_name delete an rpm package
yum list list all packages installed in the current system
yum search package_name search for packages in the rpm repository
yum clean packages clear rpm cache delete downloaded packages
yum clean headers delete all header files
yum clean all remove all cached packages and header files

back to top index ^

DEB packages (Debian, Ubuntu and similar systems)
dpkg -i package.deb install/update a deb package
dpkg -r package_name remove a deb package
dpkg from the system -l show all installed deb packages on the system
dpkg -l | grep httpd show all deb packages with "httpd" in their names
dpkg -s package_name get information about a particular package installed in the system
dpkg -L package_name show the system A list of files provided by a deb package that has been installed in
dpkg --contents package.deb Display a list of files provided by a package that has not been installed
dpkg -S /bin/ping Confirm which deb package provides the given file

Return to top index ^

APT software tools (Debian, Ubuntu and similar systems)
apt-get install package_name install/update a deb package
apt-cdrom install package_name install/update a deb package from a CD
apt-get update upgrade a package in the list
apt-get upgrade upgrade All installed software apt -
get remove package_name Removes a deb package from the system apt
-get check Confirms that dependent software repositories are correct Package name of the string Return to top index^ View file contents cat file1 View the contents of a file forward from the first byte tac file1 View the contents of a file backward from the last line more file1 View the contents of a long file less file1 Similar to the 'more' command, but it allows the same reverse operation in a file as the forward operation head -2 file1 to see the first two lines of a file tail -2 file1 to see the last two lines of a file tail -f /var/log /messages View content added to a file in real time Back to Top Index^ Text Processing

















cat file1 file2 ... | command <> file1_in.txt_or_file1_out.txt general syntax for text manipulation using PIPE, STDIN and STDOUT
cat file1 | command( sed, grep, awk, grep, etc...) > result.txt Detail text of a file and write the brief to a new file
cat file1 | command( sed, grep, awk, grep, etc...) >> result.txt Combine the detailed text of a file and write the brief into an existing file
grep Aug /var/log/messages Find the keyword "Aug" in the file '/var/log/messages'
grep ^Aug /var/log/messages in the file '/var/log/messages ' find words starting with "Aug"
grep [0-9] /var/log/messages select all lines containing numbers in '/var/log/messages' file
grep Aug -R /var/log/* in directory Search for the string "Aug" in '/var/log' and subsequent directories
sed 's/stringa1/stringa2/g' example.txt Replace "string1" in example.txt with "string2"
sed ' /^$/d' example.txt removes all blank lines from the example.txt file
sed '/ *#/d; /^$/d' example.txt remove all comments and blank lines from example.txt file
echo 'esempio' | tr '[:lower:]' '[:upper:]' merge top and bottom cell contents
sed -e '1d' result.txt exclude first line from file example.txt
sed -n '/stringa1/p' view lines containing only word "string1"
sed -e 's/ *$/ /' example.txt remove whitespace at the end of each line
sed -e 's/stringa1//g' example.txt remove only the word "string1" from the document and keep all the rest
sed -n '1,5p;5q' example .txt View contents from first line to 5th line
sed -n '5p;5q' example.txt View line 5
sed -e 's/00*/0/g' example.txt Replace multiple zeros with a single zero
cat -n file1 mark the number of lines in the file
cat example.txt | awk 'NR%2==1' delete all even lines in the example.txt file
echo abc | awk '{print $1}' view the first column of a line
echo abc | awk '{print $1,$3}' View the first and third columns of a line
paste file1 file2 Merge the contents of two files or two columns
paste -d '+' file1 file2 Merge the contents of two files or two columns, use "+" in the middle to distinguish
sort file1 file2 Sort the contents of two files
sort file1 file2 | uniq Take out the union of two files (duplicate lines only Keep one copy)
sort file1 file2 | uniq -u delete the intersection, leaving other lines
sort file1 file2 | uniq -d take out the intersection of two files (leave only files that exist in both files)
comm -1 file1 file2 compares the contents of two files and deletes only the contents of 'file1'
comm -2 file1 file2 compares the contents of two files and deletes only the contents of 'file2'
comm -3 file1 file2 compares the contents of two files and deletes only two Parts common to all files

Return to top index ^


Character settings and file format conversion
dos2unix filedos.txt fileunix.txt Converts the format of a text file from MSDOS to UNIX
unix2dos fileunix.txt filedos.txt Converts the format of a text file from UNIX to MSDOS
recode ..HTML < page.txt > page. html convert a text file to html
recode -l | more show all allowed conversion formats

back to top index^

filesystem analysis
badblocks -v /dev/hda1 Check for bad blocks on disk hda1
fsck /dev/hda1 repair/check integrity of linux filesystem on hda1 disk fsck.ext2 /dev/hda1 repair/check
integrity of ext2 filesystem on hda1 disk
e2fsck /dev/hda1 repair/check ext2 filesystem on hda1 disk Integrity
e2fsck -j /dev/hda1 repair/check integrity of ext3 filesystem on hda1 disk fsck.ext3 /dev/hda1 repair/check integrity
of ext3 filesystem on hda1 disk
fsck.vfat /dev/hda1 repair/ Check the integrity of the fat file system on the hda1 disk
fsck.msdos /dev/hda1 Repair/Check the integrity of the dos file system on the hda1 disk
dosfsck /dev/hda1 Repair/Check the integrity of the dos file system on the hda1 disk

Back to top index^

Initialize a file system
mkfs /dev/hda1 Create a file system
mke2fs /dev/hda1 in the hda1 partition Create a linux ext2 file system
mke2fs -j /dev/hda1 Create a linux ext3 (journaled) in the hda1 partition Filesystem
mkfs -t vfat 32 -F /dev/hda1 Create a FAT32 filesystem
fdformat -n /dev/fd0 Format a floppy disk
mkswap /dev/hda3 Create a swap filesystem

Back to top index^

SWAP file system
mkswap /dev/hda3 Create a swap file system
swapon /dev/hda3 Enable a new swap file system
swapon /dev/hda2 /dev/hdb3 Enable two swap partitions

Back to top index ^

backup
dump -0aj -f / tmp/home0.bak /home make a full backup of the '/home' directory
dump -1aj -f /tmp/home0.bak /home make an interactive backup of the '/home' directory
restore -if /tmp/home0.bak Restore an interactive backup
rsync -rogpav --delete /home /tmp Sync directories on both sides
rsync -rogpav -e ssh --delete /home ip_address:/tmp rsync via SSH tunnel
rsync -az -e ssh --delete ip_addr:/ home/public /home/local Sync a remote directory to a local directory via ssh and zip
rsync -az -e ssh --delete /home/local ip_addr:/home/public Sync a local directory to a remote directory via ssh and zip
dd bs=1M if=/dev/hda | gzip | ssh user@ip_addr 'dd of=hda.gz' Perform an operation of backing up the local disk on the remote host through ssh
dd if=/dev/sda of=/tmp/file1 Backup disk contents to a file
tar -Puf backup.tar /home/user Perform an interactive backup of the '/home/user' directory
( cd /tmp/local / && tar c . ) | ssh -C user@ip_addr 'cd /home/share/ && tar x -p' Copy a directory content in a remote directory via ssh
( tar c /home ) | ssh -C user@ip_addr ' cd /home/backup-home && tar x -p' Copy a local directory in a remote directory via ssh
tar cf - . | (cd /tmp/backup ; tar xf - ) Copy a directory locally to another, keep Original permissions and links
find /home/user1 -name '*.txt' | xargs cp -av --target-directory=/home/backup/ --parents Find and copy all files ending with '.txt' from a directory file to another directory
find /var/log -name '*.log' | tar cv --files-from=- | bzip2 > log.tar.bz2 find all files starting with '.log' End the file and make a bzip package
dd if=/dev/hda of=/dev/fd0 bs=512 count=1 Make an action to copy the MBR (Master Boot Record) content to the floppy disk
dd if=/dev/fd0 of=/dev/hda bs=512 count=1 Restore MBR contents from a backup already saved to floppy

Back to top index^

CD
cdrecord -v gracetime=2 dev=/dev/cdrom -eject blank=fast -force Empty a rewritable CD
mkisofs /dev/cdrom > cd.iso Create a CD iso image file on the disk
mkisofs /dev/cdrom | gzip > cd_iso.gz Create a compressed CD iso image on disk
mkisofs -J -allow-leading-dots -R -V "Label CD" -iso-level 4 -o ./cd .iso data_cd Create a directory iso image file
cdrecord -v dev=/dev/cdrom cd.iso Burn an ISO image file
gzip -dc cd_iso.gz | cdrecord dev=/dev/cdrom - Burn a compressed ISO image file
mount -o loop cd.iso /mnt/iso mounts an ISO image file
cd-paranoia -B rips tracks from a CD to a wav file
cd-paranoia -- "-3" rips tracks from a CD to wav file (parameter -3)
cdrecord --scanbus scan the bus to identify scsi channels
dd if=/dev/hdc | md5sum check the md5sum encoding of a device, such as a CD

return top index ^

network - (Ethernet and WIFI wireless)
ifconfig eth0 show the configuration of an ethernet card
ifup eth0 enable a 'eth0' network device
ifdown eth0 disable a 'eth0' network device
ifconfig eth0 192.168.1.1 netmask 255.255.255.0 control IP address
ifconfig eth0 promisc set 'eth0' to promiscuous mode to sniff sniffing
dhclient eth0 enable 'eth0' in dhcp mode
route -n show routing table
route add -net 0/0 gw IP_Gateway configura default gateway
route add -net 192.168.0.0 netmask 255.255.0.0 gw 192.168.1.1 configure static route to reach network '192.168.0.0/16'
route del 0/0 gw IP_gateway remove static route
echo "1" > /proc/sys/net/ipv4/ip_forward activate ip routing
hostname show hostname of system
host www.example. com lookup hostname to resolve name to ip address and viceversa(1)
nslookup www.example.com lookup hostname to resolve name to ip address and viceversa(2)
ip link show show link status of all interfaces
mii-tool eth0 show link status of 'eth0'
ethtool eth0 show statistics of network card 'eth0'
netstat -tup show all active network connections and their PID
netstat -tupl show all network services listening on the system and their PID
tcpdump tcp port 80 show all HTTP traffic
iwlist scan show wireless networks
iwconfig eth1 show configuration of a wireless network card
hostname show hostname
host www.example.com lookup hostname to resolve name to ip address and viceversa
nslookup www.example.com lookup hostname to resolve name to ip address and viceversa
whois www.example.com lookup on Whois database

GO TOP INDEX ^
Microsoft Windows networks (SAMBA)
nbtscan ip_addr netbios name resolution
nmblookup -A ip_addr netbios name resolution
smbclient -L ip_addr/hostname show remote shares of a windows host
smbget -Rr smb://ip_addr/share like wget can download files from a host windows via smb
mount -t smbfs -o username=user,password=pass //WinClient/share /mnt/share mount a windows network share

转自:http://www.php100.com/html/webkaifa/Linux/2009/1106/3485.html

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326679305&siteId=291194637