In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)06/01 Report--
1. Tar
Create a new tar file
$tar cvf archive_name.tar dirname/
Extract the tar file
$tar xvf archive_name.tar
View the tar file
$tar tvf archive_name.tar
More examples: The Ultimate Tar Command Tutorial with 10 Practical Examples
2. Grep
Look for strings in the file (case-insensitive)
$grep-I "the" demo_file
Output the line that matches successfully, and the three lines after that line
$grep-A 3-I "example" demo_text
Recursively query the file containing the specified string in a folder
$grep-r "ramesh" *
More examples: Get a Grip on the Grep!-15 Practical Grep Command Examples
3. Find
Find the file with the specified file name (case-insensitive)
$find-iname "MyProgram.c"
Execute a command on the found file
$find-iname "MyProgram.c"-exec md5sum {}\
Find all empty files in the home directory
$find ~-empty
More examples: Mommy, I found it!-15 Practical Linux Find Command Examples
4. Ssh
Log in to the remote host
$ssh-l jsmith remotehost.example.com
Debug ssh client
$ssh-v-l jsmith remotehost.example.com
Show ssh client version
$ssh-V
More examples: 5 Basic Linux SSH Client Commands
5. Sed
When you copy a file from the Dos system to Unix/Linux, each line of the file ends with\ r\ n.sed can easily convert it to a file in Unix format, using the file at the end.
$sed's Universe. Filename.
Reverse the contents of the file and output
$sed-n'1g; h; p 'filename
Add a line number to a non-blank line
$sed'/. / = 'thegeekstuff.txt | sed' N; s /\ n / /'
More examples: Advanced Sed Substitution Examples
6. Awk
Delete duplicate lines
$awk'! ($0 in array) {array [$0]; print} 'temp
Print all lines in / etc/passwd that contain the same uid and gid
$awk-F':'$3 million 4' / etc/passwd
Print the fields of the specified part of the file
$awk'{print $2J 5;} 'employee.txt
More examples: 8 Powerful Awk Built-in Variables-FS, OFS, RS, ORS, NR, NF, FILENAME, FNR
7. Vim
Open the file and skip to line 10
$vim + 10 filename.txt
Open the file and skip to the first matching line
$vim + / search-term filename.txt
Open a file in read-only mode
$vim-R / etc/passwd
More examples: How To Record and Play in Vim Editor
8. Diff
Ignore the white space character when comparing
$diff-w name_list.txt name_list_new.txt9. Sort
Sort the contents of the file in ascending order
$sort names.txt
Sort the contents of the file in descending order
$sort-r names.txt
Sort the contents of / etc/passwd by the third field
$sort-t:-k 3n / etc/passwd | more10. Export
Output environment variables that match the string oracle
$export | grep ORCALEdeclare-x ORACLE_BASE= "/ u01/app/oracle" declare-x ORACLE_HOME= "/ u01/app/oracle/product/10.2.0" declare-x ORACLE_SID= "med" declare-x ORACLE_TERM= "xterm"
Set global environment variables
$export ORACLE_HOME=/u01/app/oracle/product/10.2.011. Xargs
Copy all picture files to an external drive
$ls * .jpg | xargs-N1-I cp {} / external-hard-drive/directory
Compress and package all jpd files in the system
$find /-name * .jpg-type f-print | xargs tar-cvzf p_w_picpaths.tar.gz
Download all url pages listed in the file
$cat url-list.txt | xargs wget-c12. Ls
Displays the file size in an easy-to-read way (displayed as MB,GB...)
$ls-lh-rw-r- 1 ramesh team-dev 8.9m Jun 12 15:27 arch-linux.txt.gz
Output the file in the last modified time-rise sequence
$ls-ltr
Display the file type after the file name
$ls-F
More examples: Unix LS Command: 15 Practical Examples
13. Pwd
Output current working directory
14. Cd
Cd-you can switch between the two most recent working directories
Using shopt-s cdspell, you can set up automatic spell checking of cd commands
More examples: 6 Awesome Linux cd command Hacks
15. Gzip
Create a * .gz zip file
$gzip test.txt
Extract the * .gz file
$gzip-d test.txt.gz
Show the ratio of compression
$gzip-l * .gz compressed uncompressed ratio uncompressed_name 23709 97975 75.8% asp-patch-rpms.txt16. Bzip2
Create a * .bz2 zip file
$bzip2 test.txt
Extract the * .bz2 file
Bzip2-d test.txt.bz2
More examples: BZ is Eazy! Bzip2, bzgrep, bzcmp, bzdiff, bzcat, bzless, bzmore examples
17. Uzip
Extract the * .zip file
$unzip test.zip
View the contents of the * .zip file
Unzip-l jasper.zipArchive: jasper.zipLength Date Time Name--40995 11-30-98 23:50 META-INF/MANIFEST.MF32169 08-25-98 21:07 classes_15964 08-25-98 21:07 classes_names10542 08-25-98 21:07 classes_ncomp18. Shutdown
Shut down the system and shut down the computer immediately
$shutdown-h now
Turn off the phone in 10 minutes
$shutdown-h + 10
Restart
$shutdown-r now
Force a system check during restart
$shutdown-Fr now19. Ftp
The use of the ftp command and the sftp command is basically similar. Connect to the ftp server and download multiple files.
$ftp IP/hostnameftp > mget * .html
Display a list of files on the remote host
Ftp > mls * .html-/ ftptest/features.html/ftptest/index.html/ftptest/othertools.html/ftptest/samplereport.html/ftptest/usage.html
More examples: FTP and SFTP Beginners Guide with 10 Examples
20. Crontab
View a user's crontab entry
$crontab-u john-l
Set up a scheduled task to be executed every ten minutes
* / 10 * / home/ramesh/check-disk-space
More examples: Linux Crontab: 15 Awesome Cron Job Examples
21. Service
The service command is used to run System V init scripts, which are usually located in the / etc/init.d file. This command can run the scripts in this folder directly without adding a path.
View service status
$service ssh status
View all service statu
$service-status-all
Restart the service
$service ssh restart22. Ps
The ps command is used to display information about running processes. The ps command has many options, and only a few are listed here.
View all currently running processes
$ps-ef | more
Displays the currently running process in a tree structure, and the H option indicates the hierarchy of the display process
$ps-efH | more23. Free
This command is used to display the current memory usage of the system, including used memory, available memory, and swapped memory
By default, free outputs memory usage in bytes
$free total used free shared buffers cachedMem: 3566408 1580220 1986188 0 203988 902960 Mozilla + buffers/cache: 473272 3093136Swap: 4000176 04000176
If you want to output memory usage in other units, you need to add an option,-g: GB,-m, MB,-k, KB,-b, bytes.
$free-g total used free shared buffers cachedMem: 3 1 1 0 0 Muhammad + buffers/cache: 0 2Swap: 3 0 3
If you want to see a summary of all memory, use the-t option, which will add a summary line to the output
Ramesh@ramesh-laptop:~$ free-t total used free shared buffers cachedMem: 3566408 1592148 1974260 0 204260 912556 3091076Swap + buffers/cache: 475332 3091076Swap: 40001760 4000176Total: 7566584 1592148 597443624. Top
The top command displays the most resource-intensive processes in the current system (sorted by CPU by default). If you want to change the sorting method, you can click O (uppercase O) in the results list to display all the columns available for sorting, at which point you can select the columns you want to sort.
Current Sort Field: P for window 1:DefSelect sort field via field letter, type any other key to return a: PID = Process Id v: nDRT = Dirty Pages count d: UID = User Id y: WCHAN = Sleeping in Function e: USER = User Name z: Flags = Task Flags.
If you want to display only the processes of a specific user, you can use the-u option
$top-u oracle
More examples: Can You Top This? 15 Practical Linux Top Command Examples
25. Df
Displays the disk usage of the file system. By default, df-k will output disk usage in bytes.
$df-kFilesystem 1K-blocks Used Available Use% Mounted on/dev/sda1 29530400 3233104 24797232 12% / / dev/sda2 120367992 50171596 64082060 44% / home
Use the-h option to display disk usage in a way that is more consistent with reading habits
$df-hFilesystem Size Used Avail Capacity iused ifree% iused Mounted on/dev/disk0s2 232Gi 84Gi 148Gi 37% 21998562 38864868 36% / devfs 187Ki 187Ki 0Bi 100% 648 0% / devmap-hosts 0Bi 0Bi 0Bi 100% 00 100% / netmap Auto_home 0Bi 0Bi 0Bi 100% / home/dev/disk0s4 466Gi 45Gi 421Gi 10% 112774 0% / Volumes/BOOTCAMP//app@izenesoft.cn/public 2.7Ti 1.3Ti 1.4Ti 48% 018446744073709551615.0% / Volumes/public
Use the-T option to display the file system type
$df-TFilesystem Type 1K-blocks Used Available Use% Mounted on/dev/sda1 ext4 29530400 3233120 24797216 12% / / dev/sda2 ext4 120367992 50171596 64082060 44% / home26. Kill
Kill is used to terminate a process. Usually we will first use ps-ef to find a process to get its process number, and then use the kill-9 process number to terminate the process. You can also use killall, pkill, and xkill to terminate the process.
$ps-ef | grep vimramesh 7243 7222 9 22:43 pts/2 00:00:00 vim$ kill-9 7243
More examples: 4 Ways to Kill a Process-kill, killall, pkill, xkill
twenty-seven。 Rm
Confirm before deleting the file
$rm-I filename.txt
It is useful to use the meta character of shell in the file name. Print the file name and confirm it before deleting the file
$rm-I file*
Recursively delete all files under the folder and delete the folder
$rm-r example28. Cp
Copy file 1 to file 2 and maintain the permissions, ownership, and timestamp of the file
$cp-p file1 file2
Copy file1 to file2, and prompt whether to overwrite if file2 exists
$cp-I file1 file229. Mv
Rename the file name file1 to file2, and prompt whether to overwrite if file2 exists
$mv-I file1 file2
Note that if you use the-f option, you will not be prompted
-v outputs the renaming process, which is convenient when the file name contains wildcards
$mv-v file1 file230. Cat
You can view the contents of more than one file at a time. The following command prints the contents of file1 first, then the contents of file2.
$cat file1 file2
The-n command can precede each line with a line number
Cat-n / etc/logrotate.conf 1 / var/log/btmp {2 missingok 3 monthly 4 create 0660 root utmp 5 rotate 1 6} 31. Mount
If you want to mount a file system, you need to create a directory first, and then mount the file system to this directory
# mkdir / u01# mount / dev/sdb1 / u01
You can also add it to fstab for automatic mount, so that whenever the system restarts, the file system will be loaded.
/ dev/sdb1 / u01 ext2 defaults 0 232. Chmod
Chmod is used to change the permissions of files and directories
Give all permissions to the owner and group of the specified file (including read, write, execute)
$chmod ug+rwx file.txt
Deletes all permissions belonging to the group of the specified file
$chmod g-rwx file.txt
Modify the permissions of the directory and recursively modify the permissions of all files and subdirectories under the directory
$chmod-R ug+rwx file.txt
More examples: 7 Chmod Command Examples for Beginners
thirty-three。 Chown
Chown is used to change file owners and groups
At the same time, change the owner of a file to oracle and the group to db.
$chown oracle:dba dbora.sh
Use the-R option to recursively modify the directory and the files under the directory
$chown-R oracle:dba / home/oracle34. Passwd
Passwd is used to change the password on the command line. Using this command will require you to enter the old password first, and then enter the new password.
$passwd
Superusers can use this command to change the passwords of other users. There is no need to enter the user's password at this time.
# passwd USERNAME
Passwd can also delete a user's password. Only root users can operate this command. After deleting the password, the user can log in to the system without entering the password.
# passwd-d USERNAME35. Mkdir
Create a directory called temp under the home directory
$mkdir ~ / temp
Use the-p option to create a directory that does not exist on the path
$mkdir-p dir1/dir2/dir3/dir4/36. Ifconfig
Ifconfig is used to view and configure the network interface of the Linux system
View all network interfaces and their status
$ifconfig-a
Use the up and down commands to start or stop an interface
$ifconfig eth0 up$ ifconfig eth0 down
More examples: Ifconfig: 7 Examples To Configure Network Interface
thirty-seven。 Uname
Uname can display some important system information, such as kernel name, hostname, kernel version number, processor type and so on.
$uname-aLinux john-laptop 2.6.32-24-generic # 41-Ubuntu SMP Thu Aug 19 01:12:52 UTC 2010 i686 GNU/Linux38. Whereis
You can use the whereis command when you don't know the location of a command. Use whereis to find the location of ls
$whereis lsls: / bin/ls / usr/share/man/man1/ls.1.gz / usr/share/man/man1p/ls.1p.gz
When you want to find the location of an executable program, but the program is not in the default directory of whereis, you can use the-B option and specify the directory as the parameter for this option. The following command looks for the lsmk command in the / tmp directory
$whereis-u-B / tmp-f lsmklsmk: / tmp/lsmk39. Whatis
Wathis displays the description of a command
$whatis lsls (1)-list directory contents$ whatis ifconfigifconfig (8)-configure a network interface40. Locate
Locate naming shows the path to a specified file (or set of files), which uses a database created by updatedb
The following command displays all files on the system that contain crontab strings
$locate crontab/etc/anacrontab/etc/crontab/usr/bin/crontab/usr/share/doc/cron/examples/crontab2english.pl.gz/usr/share/man/man1/crontab.1.gz/usr/share/man/man5/anacrontab.5.gz/usr/share/man/man5/crontab.5.gz/usr/share/vim/vim72/syntax/crontab.vim41. Man
Display the man page of a command
$man crontab
Some commands may have multiple man pages, with each man page corresponding to a command type
$man SECTION-NUMBER commandname
Man pages can generally be divided into eight command types
User command
System call
C library function
Device and network interface
file format
Games and screensavers
Environment, tables, macros
System administrator commands and background running commands
For example, when we execute whatis crontab, you can see that crontab has two command types 1 and 5, so we can view the man page of command type 5 with the following command
$whatis crontabcrontab (1)-maintain crontab files for individual users (V3) crontab (5)-tables for driving cron$ man 5 crontab42. Tail
The tail command displays the last 10 lines of text of the file by default
$tail filename.txt
You can use the-n option to specify the number of rows to display
$tail-n N filename.txt
You can also use the-f option for real-time viewing, which waits after execution. If new lines are added to the end of the file, it will continue to output new lines, which is very useful when viewing logs. You can terminate the execution of the command through CTRL-C
$tail-f log-file
More examples: 3 Methods To View tail-f output of Multiple Log Files in One Terminal
forty-three。 Less
This name displays the contents of the file without loading the entire file, which is useful when viewing large log files
$less huge-log-file.log
When you open a file with the less command, the following two buttons will help you a lot. They are used to scroll forward and backward.
CTRL+F-forward one windowCTRL+B-backward one window
More examples: Unix Less Command: 10 Tips for Effective Navigation
forty-four。 Su
The su command is used to switch user accounts. Superusers can use this command to switch to any other user without entering a password
$su-USERNAME
Execute a command with another user name in the following example, the user john executes the ls command using the raj user name, and returns the john account after execution
[john@dev-server] $su-raj-c 'ls' [john@dev-server] $
Log in with the specified user and use the specified shell program instead of the default
$su-s' SHELLNAME' USERNAME45. Mysql
Mysql is probably the most widely used database on Linux, and even if you don't have mysql installed on your server, you can use the mysql client to connect to a remote mysql server
To connect to a remote database, a password is required
$mysql-u root-p-h 192.168.1.2
Connect to the local database
$mysql-u root-p
You can also enter the database password on the command line, just add the password after-p as an argument, and you can write it directly after p without adding a space
forty-six。 Yum
Install apache using yum
$yum install httpd
Update apache
$yum update httpd
Uninstall / remove apache
$yum remove httpd47. Rpm
Install apache using rpm
# rpm-ivh httpd-2.2.3-22.0.1.el5.i386.rpm
Update apache
# rpm-uvh httpd-2.2.3-22.0.1.el5.i386.rpm
Uninstall / remove apache
# rpm-ev httpd
More examples: RPM Command: 15 Examples to Install, Uninstall, Upgrade, Query RPM Packages
forty-eight。 Ping
Ping one remote host, sending only 5 packets
$ping-c 5 gmail.com
More examples: Ping Tutorial: 15 Effective Ping Command Examples
forty-nine。 Date
Set system date
# date-s "01Compact 31Universe 23:59:53"
When you modify the system time, you need to synchronize the hardware time with the system time
# hwclock-systohc# hwclock-systohc-utc50. Wget
Download software, music and videos from the Internet using wget
$wget http://prdownloads.sourceforge.net/sourceforge/nagios/nagios-3.2.1.tar.gz
Download the file and save it with the specified file name
$wget-O taglist.zip http://www.vim.org/scripts/download_script.php?src_id=7701
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.