×ðÁú¿­Ê±¹ÙÍøµÇ¼

×îÈ«LinuxÏÂÁî´óÈ«£¬½¨ÒéÕä²Ø£ ¡£ ¡£¡

Ç°ÑÔ

LinuxºÍwindowsÏà±È£¬Ðí¶à¹Ü¿Ø¶¼ÐèÒªÓÃÏÂÁîÀ´²Ù×÷ ¡£windowsÒÔÖ±¹ÛµÄ¿ÉÊÓ»¯µÄ·½·¨²Ù×÷£¬ÌØÊâÊʺÏÔÚ×ÀÃæ¶ËPCÉϲÙ×÷Ö´ÐÐÏìÓ¦µÄÈí¼þ ¡£

¶øLinuxÏÂÁîÐз½·¨µÄ²Ù×÷£¬ÌØÊâÊÇÔÚЧÀÍÆ÷¶Ë±à³Ì¡¢ÖÎÀí¡¢ÔËά·½Ã棬Խ·¢¼òÆÓ¡¢¶ÌС¡¢¾«º· ¡£¶Ì¶ÌÒ»ÐÐ×éºÏÏÂÁ¼´¿ÉÍê³ÉÔÚwindowsÐèÒªÖÖÖÖ¼Ó¹¤¡¢ÕûºÏµÄÖØ´ó¸ßЧµÄ¹¦Ð§²Ù×÷ ¡£

1.Àú³ÌÖÎÀí

w ÏÔʾĿ½ñÔÚÏßÓû§ÇéÐÎ

my_adm pts/0    111.111.111.111    Èý15   24:58   2:51   0.02s sshd: my_admin [priv]root     pts/3    111.111.111.112      13:15    3:47m  0.35s  0.35s -bashmy_adm pts/5    111.111.111.113    15:14    2.00s  0.54s  0.02s sshd: my_admin [priv]

µÇ¼ºó¸´ÖÆ

pkill -kill -t pts/?? ɱµôÖ¸ÃüÃû×ÖµÄÀú³Ì£¬ÈçÉÏÊöµÄpts/5

´«ËÍÃÅ£ºLinuxÖÐKillÀú³ÌµÄNÖÖÒªÁì

2.ϵͳÐÅÏ¢

arch ÏÔʾ»úеµÄ´¦ÀíÆ÷¼Ü¹¹(1) uname -m ÏÔʾ»úеµÄ´¦ÀíÆ÷¼Ü¹¹(2) uname -r ÏÔʾÕýÔÚʹÓõÄÄں˰汾 dmidecode -q ÏÔʾӲ¼þϵͳ²¿¼þ - (SMBIOS / DMI) hdparm -i /dev/hda ö¾ÙÒ»¸ö´ÅÅ̵ļܹ¹ÌØÕ÷ hdparm -tT /dev/sda ÔÚ´ÅÅÌÉÏÖ´ÐвâÊÔÐÔ¶ÁÈ¡²Ù×÷ cat /proc/cpuinfo ÏÔʾCPU infoµÄÐÅÏ¢ cat /proc/interrupts ÏÔʾÖÐÖ¹ cat /proc/meminfo УÑéÄÚ´æʹÓà cat /proc/swaps ÏÔʾÄÄЩswap±»Ê¹Óà cat /proc/version ÏÔʾÄں˵İ汾 cat /proc/net/dev ÏÔʾÍøÂçÊÊÅäÆ÷¼°Í³¼Æ cat /proc/mounts ÏÔʾÒѼÓÔصÄÎļþϵͳ lspci -tv ö¾Ù PCI ×°±¸ lsusb -tv ÏÔʾ USB ×°±¸ date ÏÔʾϵͳÈÕÆÚ ctime=`date +%Y-%m-%dT%k:%M:%S` #ÃûÌû¯Ê±¼ä£¬Èç2018-01-13T11:09:19£¬ ×¢ÖØ%k Óë %HµÄÇø±ð£¬Ç°Õß·µ»Ø9£¬ºóÕß·µ»Ø09.YESTERDAY=`date +%Y-%m-%d -d "-1 days"` »ñÈ¡×òÈÕÈÕÆÚcal 2007 ÏÔʾ2007ÄêµÄÈÕÀú±í date 041217002007.00 ÉèÖÃÈÕÆÚºÍʱ¼ä - ÔÂÈÕʱ·ÖÄê.Ãë clock -w ½«Ê±¼äÐÞ¸ÄÉúÑĵ½ BIOS

µÇ¼ºó¸´ÖÆ

ÅÌÎÊÍø¹ØµØµã(È罫centosЧÀÍÆ÷ÍøÂç»ñÈ¡ÀàÐÍÓÉdhcpÇл»Îªstaticʱ,ÐèÒª»ñÈ¡µ½ip¼°Íø¹ØÐÅÏ¢¾ÙÐй̻¯ÉèÖÃʱ»áÓõ½,ÈçÍâµØipΪ10.34.0.123,Ôòͨ¹ýÈçÏÂÏÂÁîÅÌÎʵ½Íø¹ØΪµÚÒ»¸ö3.254):

[root@file-server ~]# netstat -rnKernel IP routing tableDestination     Gateway         Genmask         Flags   MSS Window  irtt Iface0.0.0.0         10.34.3.254     0.0.0.0         UG        0 0          0 enp3g010.34.0.0       0.0.0.0         255.255.252.0   U         0 0          0 enp3g0192.168.1.0     0.0.0.0         255.255.255.0   U         0 0          0 virbr0

µÇ¼ºó¸´ÖÆ

CentOS / RedHat ϵÁÐ,Éó²é²Ù×÷ϵͳÐÅÏ¢(ÈôÊÇûÓÐlsb_releaseÏÂÁî, ʹÓÔyum install redhat-lsb”×°ÖÃ):

[root@server-test online]# lsb_release -aLSB Version: :core-4.1-amd64:core-4.1-noarchDistributor ID: CentOSDescription: CentOS Linux release 7.5.1804 (Core) Release: 7.5.1804Codename: Core

µÇ¼ºó¸´ÖÆ

3.¹Ø»ú (ϵͳµÄ¹Ø»ú¡¢ÖØÆôÒÔ¼°µÇ³ö )

shutdown -h now ¹Ø±Õϵͳ(1) init 0 ¹Ø±Õϵͳ(2) telinit 0 ¹Ø±Õϵͳ(3) shutdown -h hours:minutes & °´Ô¤×¼Ê±¼ä¹Ø±Õϵͳ shutdown -c ×÷·Ï°´Ô¤×¼Ê±¼ä¹Ø±Õϵͳ shutdown -r now ÖØÆô(1) reboot ÖØÆô(2) logout ×¢Ïú

µÇ¼ºó¸´ÖÆ

4.ÎļþºÍĿ¼

cd /home ½øÈë '/ home' Ŀ¼' cd .. ·µ»ØÉÏÒ»¼¶Ä¿Â¼ cd ../.. ·µ»ØÉÏÁ½¼¶Ä¿Â¼ cd ½øÈëСÎÒ˽È˵ÄÖ÷Ŀ¼ cd ~user1 ½øÈëСÎÒ˽È˵ÄÖ÷Ŀ¼ cd - ·µ»ØÉÏ´ÎËùÔÚµÄĿ¼ pwd ÏÔʾÊÂÇé·¾¶ ls Éó²éĿ¼ÖеÄÎļþ ls -F Éó²éĿ¼ÖеÄÎļþ ls -l ÏÔʾÎļþºÍĿ¼µÄÏêϸ×ÊÁÏ ls -a ÏÔʾÒþ²ØÎļþ ls *[0-9]* ÏÔʾ°üÀ¨Êý×ÖµÄÎļþÃûºÍĿ¼Ãû tree ÏÔʾÎļþºÍĿ¼ÓɸùĿ¼×îÏȵÄÊ÷Ðνṹ(1) lstree ÏÔʾÎļþºÍĿ¼ÓɸùĿ¼×îÏȵÄÊ÷Ðνṹ(2) mkdir dir1 ½¨ÉèÒ»¸ö½Ð×ö 'dir1' µÄĿ¼' mkdir dir1 dir2 ͬʱ½¨ÉèÁ½¸öĿ¼ mkdir -p /tmp/dir1/dir2 ½¨ÉèÒ»¸öĿ¼Ê÷ rm -f file1 ɾ³ýÒ»¸ö½Ð×ö 'file1' µÄÎļþ' rmdir dir1 ɾ³ýÒ»¸ö½Ð×ö 'dir1' µÄĿ¼' rm -rf dir1 ɾ³ýÒ»¸ö½Ð×ö 'dir1' µÄĿ¼²¢Í¬Ê±É¾³ýÆäÄÚÈÝ rm -rf dir1 dir2 ͬʱɾ³ýÁ½¸öĿ¼¼°ËüÃǵÄÄÚÈÝ mv dir1 new_dir ÖØÃüÃû/Òƶ¯ Ò»¸öĿ¼ cp file1 file2 ¸´ÖÆÒ»¸öÎļþ cp dir/* . ¸´ÖÆÒ»¸öĿ¼ÏµÄËùÓÐÎļþµ½Ä¿½ñÊÂÇéĿ¼ cp -a /tmp/dir1 . ¸´ÖÆÒ»¸öĿ¼µ½Ä¿½ñÊÂÇéĿ¼ cp -a dir1 dir2 ¸´ÖÆÒ»¸öĿ¼ ln -s file1 lnk1 ½¨ÉèÒ»¸öÖ¸ÏòÎļþ»òĿ¼µÄÈíÁ´½Ó ln file1 lnk1 ½¨ÉèÒ»¸öÖ¸ÏòÎļþ»òĿ¼µÄÎïÀíÁ´½Ó touch -t 0712250000 file1 ÐÞ¸ÄÒ»¸öÎļþ»òĿ¼µÄʱ¼ä´Á - (YYMMDDhhmm) file file1 outputs the mime type of the file as text iconv -l ÁгöÒÑÖªµÄ±àÂë 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)

µÇ¼ºó¸´ÖÆ

5.ÎļþËÑË÷

find / -name file1 ´Ó '/' ×îÏȽøÈë¸ùÎļþϵͳËÑË÷ÎļþºÍĿ¼ find / -user user1 ËÑË÷ÊôÓÚÓû§ 'user1' µÄÎļþºÍĿ¼ find /home/user1 -name \*.bin ÔÚĿ¼ '/ home/user1' ÖÐËÑË÷´øÓÐ'.bin' ×îºóµÄÎļþ find /usr/bin -type f -atime +100 ËÑË÷ÔÚÒÑÍù100ÌìÄÚδ±»Ê¹ÓùýµÄÖ´ÐÐÎļþ find /usr/bin -type f -mtime -10 ËÑË÷ÔÚ10ÌìÄÚ±»½¨Éè»òÕßÐ޻ڸĵÄÎļþ find / -name \*.rpm -exec chmod 755 '{}' \; ËÑË÷ÒÔ '.rpm' ×îºóµÄÎļþ²¢½ç˵ÆäȨÏÞ ^                        find /tmp -name \*.hprof -exec rm -f {} \;ÅúÁ¿É¾³ýjava¿ÍÕ».hprofÎļþfind / -xdev -name \*.rpm ËÑË÷ÒÔ '.rpm' ×îºóµÄÎļþ£¬ºöÂÔ¹âÇý¡¢½ÝÅ̵ȿÉÒƶ¯×°±¸ locate \*.ps Ñ°ÕÒÒÔ '.ps' ×îºóµÄÎļþ - ÏÈÔËÐÐ 'updatedb' ÏÂÁî whereis halt ÏÔʾһ¸ö¶þ½øÖÆÎļþ¡¢Ô´Âë»òmanµÄλÖà which halt ÏÔʾһ¸ö¶þ½øÖÆÎļþ»ò¿ÉÖ´ÐÐÎļþµÄÍêÕû·¾¶ grep -rn "query_string" *  LinuxĿ¼ÏÂÈ«¾Ö²éÕÒËùÓÐÎļþÖÐÊÇ·ñ°üÀ¨Ö¸¶¨×Ö·û´®£¨-r£ºµÝ¹é£»-n£ºÏÔʾÐкţ©

µÇ¼ºó¸´ÖÆ

6.¹ÒÔØÒ»¸öÎļþϵͳ

mount /dev/hda2 /mnt/hda2 ¹ÒÔØÒ»¸ö½Ð×öhda2µÄÅÌ - È·¶¨Ä¿Â¼ '/ mnt/hda2' ÒѾ­±£´æ umount /dev/hda2 жÔØÒ»¸ö½Ð×öhda2µÄÅÌ - ÏÈ´Ó¹ÒÔصã '/ mnt/hda2' Í˳ö fuser -km /mnt/hda2 µ±×°±¸Ã¦ÂµÊ±Ç¿ÖÆжÔØ umount -n /mnt/hda2 ÔËÐÐжÔزÙ×÷¶ø²»Ð´Èë /etc/mtab Îļþ- µ±ÎļþΪֻ¶Á»òµ±´ÅÅÌдÂúʱºÜÊÇÓÐÓà mount /dev/fd0 /mnt/floppy ¹ÒÔØÒ»¸öÈíÅÌ mount /dev/cdrom /mnt/cdrom ¹ÒÔØÒ»¸öcdrom»òdvdrom mount /dev/hdc /mnt/cdrecorder ¹ÒÔØÒ»¸öcdrw»òdvdrom mount /dev/hdb /mnt/cdrecorder ¹ÒÔØÒ»¸öcdrw»òdvdrom mount -o loop file.iso /mnt/cdrom ¹ÒÔØÒ»¸öÎļþ»òISO¾µÏñÎļþ mount -t vfat /dev/hda5 /mnt/hda5 ¹ÒÔØÒ»¸öWindows FAT32Îļþϵͳ mount /dev/sda1 /mnt/usbdisk ¹ÒÔØÒ»¸öusb ½ÝÅÌ»òÉÁ´æ×°±¸ mount -t smbfs -o username=user,password=pass //WinClient/share /mnt/share ¹ÒÔØÒ»¸öwindowsÍøÂç¹²Ïí

µÇ¼ºó¸´ÖÆ

7.´ÅÅÌ¿Õ¼ä

df -h ÏÔʾÒѾ­¹ÒÔصķÖÇøÁбí ls -lSr |more ÒԳߴç¾ÞϸÅÅÁÐÎļþºÍĿ¼ du -sh dir1 ¹ÀËãĿ¼ 'dir1' ÒѾ­Ê¹ÓõĴÅÅÌ¿Õ¼ä' du -sk * | sort -rn ÒÔÈÝÁ¿¾ÞϸΪÒÀ¾ÝÒÀ´ÎÏÔʾÎļþºÍĿ¼µÄ¾Þϸ rpm -q -a --qf '%10{SIZE}t%{NAME}n' | sort -k1,1n ÒÔ¾ÞϸΪÒÀ¾ÝÒÀ´ÎÏÔʾÒÑ×°ÖõÄrpm°üËùʹÓõĿռä (fedora, redhatÀàϵͳ) dpkg-query -W -f='${Installed-Size;10}t${Package}n' | sort -k1,1n ÒÔ¾ÞϸΪÒÀ¾ÝÏÔʾÒÑ×°ÖõÄdeb°üËùʹÓõĿռä (ubuntu, debianÀàϵͳ) hdfs dfs -du /dw/default | sort -rn | head -n 10 | awk '{printf("%.2f\t\t%.2f\t\t%s\t\n",$1/1024/1024/1024,"\t"$2/1024/1024/1024,"\t"$3)}'  ÅÌÎÊhdfsÎļþϵͳÖбíÎļþ¾Þϸ£¬°´´Ó´óµ½Ð¡µÄ˳ÐòÅÅÁÐ(È¡Ç°10ÁÐ)£¬µ¥Î»GB

µÇ¼ºó¸´ÖÆ

8.ϵͳ¸ºÔØ — top

top -d 20 -p 1303                             ½«Àú³ÌºÅ1303µÄϵͳ¸ºÔØ£¬Ã¿¸ô20ÃëË¢ÐÂÒ»´Î¡£Ó¢ÎÄ״̬Ï£¬°´×¡c¼ü£¬½«Õ¹Ê¾¾ÙÐеÄÏêϸÇéÐÎÐÅÏ¢£¬¹ØÓÚjava³ÌÐòµ÷ÊÔÀ´Ëµ£¬ºÜÊÇÓѺÃ¡£top -d 20 -n 3 -b > test.txt                  ÿ¸ô20Ã룬һ¹²Ö´ÐÐ3´Î£¬ ½«Í³¼ÆЧ¹ûµ¼Èëµ½test.txtÎļþÖÐ¡£

µÇ¼ºó¸´ÖÆ

topÏÂÁîÏÔʾ²»È«£¬Ìí¼Ó-w²ÎÊý£º

ÏÂÁîΪ£ºtop -b -n 1

-bΪ Åú´¦Àíģʽ£¬

-nΪˢеĴÎÊý

·¢Ã÷ÐÅÏ¢ÏÔʾ²»È«£¬×îºóman top£¬¼ÓÒ»¸ö²ÎÊýwºó£¬ÍêÈ«ÏÔʾ

top -b -n 1 -w 512

ÈôÊÇÐèÒªÏÔʾÍêÕûµÄCOMMANDÏÂÁʹÓÃtop -c²ÎÊý

top -c -bw 500

Éó²éÍêÕûÀú³ÌÃû£¬ °´500¸ö×Ö·û³¤¶ÈÉó²é£¨ÕâÑù»ù±¾¿ÉÒÔÉó²éµ½ÍêÕûµÄÏÂÁ ÆäËû²ÎÊýÁбí£¬¹Ù·½Ú¹ÊÍ£º

1. COMMAND-LINE Options       The command-line syntax for top consists of:          -hv|-bcHiOSs -d secs -n max -u|U user -p pid -o fld -w [cols]        The typically mandatory switch ('-') and even whitespace are completely optional.        -h | -v  :Help/Version            Show library version and the usage prompt, then quit.        -b  :Batch-mode operation            Starts top in Batch mode, which could be useful for sending output from top to other programs or to a file.  In this mode, top will not accept input and runs until the iterations limit you've set with the `-n' command-line option or until killed.        -c  :Command-line/Program-name toggle            Starts top with the last remembered `c' state reversed.  Thus, if top was displaying command lines, now that field will show program names, and visa versa.  See the `c' interactive command for additional information.        -d  :Delay-time interval as:  -d ss.t (secs.tenths)            Specifies the delay between screen updates, and overrides the corresponding value in one's personal configuration file or the startup default.  Later this can be changed with the `d' or `s' interactive commands.            Fractional  seconds  are honored, but a negative number is not allowed.  In all cases, however, such changes are prohibited if top is running in Secure mode, except for root (unless the `s' command-line option was used).  For additional information on            Secure mode see topic 6a. SYSTEM Configuration File.        -H  :Threads-mode operation            Instructs top to display individual threads.  Without this command-line option a summation of all threads in each process is shown.  Later this can be changed with the `H' interactive command.       -i  :Idle-process toggle            Starts top with the last remembered `i' state reversed.  When this toggle is Off, tasks that have not used any CPU since the last update will not be displayed.  For additional information regarding this toggle see topic 4c. TASK AREA Commands, SIZE.        -n  :Number-of-iterations limit as:  -n number            Specifies the maximum number of iterations, or frames, top should produce before ending.        -o  :Override-sort-field as:  -o fieldname            Specifies the name of the field on which tasks will be sorted, independent of what is reflected in the configuration file.  You can prepend a `+' or `-' to the field name to also override the sort direction.  A leading `+' will force sorting  high  to            low, whereas a `-' will ensure a low to high ordering.             This option exists primarily to support automated/scripted batch mode operation.        -O  :Output-field-names            This option acts as a form of help for the above -o option.  It will cause top to print each of the available field names on a separate line, then quit.  Such names are subject to nls translation.        -p  :Monitor-PIDs mode as:  -pN1 -pN2 ...  or  -pN1,N2,N3 ...            Monitor only processes with specified process IDs.  This option can be given up to 20 times, or you can provide a comma delimited list with up to 20 pids.  Co-mingling both approaches is permitted.             A pid value of zero will be treated as the process id of the top program itself once it is running.             This is a command-line option only and should you wish to return to normal operation, it is not necessary to quit and restart top  --  just issue any of these interactive commands: `=', `u' or `U'.            The `p', `u' and `U' command-line options are mutually exclusive.        -s  :Secure-mode operation            Starts top with secure mode forced, even for root.  This mode is far better controlled through the system configuration file (see topic 6. FILES).        -S  :Cumulative-time toggle            Starts  top  with  the  last  remembered `S' state reversed.  When Cumulative time mode is On, each process is listed with the cpu time that it and its dead children have used.  See the `S' interactive command for additional information regarding this            mode.        -u | -U  :User-filter-mode as:  -u | -U number or name            Display only processes with a user id or user name matching that given.  The `-u' option matches on  effective user whereas the `-U' option matches on any user (real, effective, saved, or filesystem).             Prepending an exclamation point ('!') to the user id or name instructs top to display only processes with users not matching the one provided.             The `p', `u' and `U' command-line options are mutually exclusive.       -w  :Output-width-override as:  -w [ number ]            In Batch mode, when used without an argument top will format output using the COLUMNS= and LINES= environment variables, if set.  Otherwise, width will be fixed at the maximum 512 columns.  With an argument, output width can be decreased or  increased            (up to 512) but the number of rows is considered unlimited.            In normal display mode, when used without an argument top will attempt to format output using the COLUMNS= and LINES= environment variables, if set.  With an argument, output width can only be decreased, not increased.  Whether using environment vari©\            ables or an argument with -w, when not in Batch mode actual terminal dimensions can never be exceeded.            Note: Without the use of this command-line option, output width is always based on the terminal at which top was invoked whether or not in Batch mode.

µÇ¼ºó¸´ÖÆ

9.Óû§ºÍȺ×é

groupadd group_name ½¨ÉèÒ»¸öÐÂÓû§×é groupdel group_name ɾ³ýÒ»¸öÓû§×é groupmod -n new_group_name old_group_name ÖØÃüÃûÒ»¸öÓû§×é useradd -c "Name Surname " -g admin -d /home/user1 -s /bin/bash user1 ½¨ÉèÒ»¸öÊôÓÚ "admin" Óû§×éµÄÓû§ useradd user1 ½¨ÉèÒ»¸öÐÂÓû§ userdel -r user1 ɾ³ýÒ»¸öÓû§ ( '-r' ɨ³ýÖ÷Ŀ¼) usermod -c "User FTP" -g system -d /ftp/user1 -s /bin/nologin user1 ÐÞ¸ÄÓû§ÊôÐÔ passwd Ð޸ĿÚÁî passwd user1 ÐÞ¸ÄÒ»¸öÓû§µÄ¿ÚÁî (Ö»ÔÊÐírootÖ´ÐÐ) chage -E 2005-12-31 user1 ÉèÖÃÓû§¿ÚÁîµÄʧЧÏÞÆÚ pwck ¼ì²é '/etc/passwd' µÄÎļþÃûÌúÍÓï·¨ÐÞÕýÒÔ¼°±£´æµÄÓû§ grpck ¼ì²é '/etc/passwd' µÄÎļþÃûÌúÍÓï·¨ÐÞÕýÒÔ¼°±£´æµÄȺ×é newgrp group_name ÉÏ°¶½øÒ»¸öеÄȺ×éÒԸıäн¨ÉèÎļþµÄÔ¤ÉèȺ×é

µÇ¼ºó¸´ÖÆ

°¸Àý 1£º

1-½¨ÉèÓû§¡¢2-×·¼Ó¸½¼Ó×é¡¢3-ɾ³ý¸½¼Ó×é

useradd san_zhang -mpasswd san_zhang san_zhang@163.com

µÇ¼ºó¸´ÖÆ

´Ó¹ÜµÀÊä³öÖÐÐÞ¸ÄÃÜÂë(ÈôÊÇ·ÇrootÇÒ¿ÉÒÔתΪroot£¬ÇëʹÓÃsudo)

echo san_zhang@163.com | sudo passwd --stdin san_zhang

µÇ¼ºó¸´ÖÆ

2 ½«san_zhang×·¼Óµ½¸½¼Ó×éhdfsÖÐ

¿ÉÒÔÌí¼Ó¶à¸ö¸½¼Ó×飬¶à¸ö×éÖ®¼äÓÿոñÀë¸ô£¬Èç”hdfs,yarn,spark”)£¬ÆäĬÈÏÔÚsan_zhangÖÐ

usermod -aG hdfs san_zhang

µÇ¼ºó¸´ÖÆ

´ËʱÉó²éÆäËùÔÚµÄÓû§×飬¿ÉÒÔ·¢Ã÷ÆäËùÊô×éΪsan_zhang£¬¸½¼Ó×éΪhdfs£¬ÈçÏ£º

id san_zhanguid=1001(san_zhang) gid=1001(san_zhang) groups=1001(san_zhang),992(hdfs)

µÇ¼ºó¸´ÖÆ

ÒýÉ꣺ÈôÊÇÉÏÒ»²½Ë³Ðòд´í£¬Îó½«hdfs×·¼Óµ½san_zhangÓû§×éÖУ¬ÈçʹÓÃÁËÈçϹýʧµÄÏÂÁ

usermod -aG san_zhang hdfs

µÇ¼ºó¸´ÖÆ

Ôò´ËʱÉó²éhdfsËùÊô×飬¾Í»á·¢Ã÷ÆäÒ²ÔÚsan_zhang×éÏÂÁË ¡£ÁíÍ⣬ËÑË÷ÃñÖÚºÅLinux¾Í¸ÃÕâÑùѧºǫ́»Ø¸´¡°Linux¡±£¬»ñÈ¡Ò»·Ý¾ªÏ²Àñ°ü ¡£

id hdfsuid=995(hdfs) gid=992(hdfs) groups=992(hdfs),994(hadoop),1001(san_zhang)

µÇ¼ºó¸´ÖÆ

ÕâʱÔÙÉó²ésan_zhang×飬¾Í»á¿´µ½Îó¼ÓÈëµÄhdfsÓû§ÁË

groups san_zhangsan_zhang : san_zhang hdfs

µÇ¼ºó¸´ÖÆ

3 ´Ósan_zhang×éÖÐɾ³ýÎó¼ÓÈëµÄhdfsÓû§

gpasswd -d hdfs san_zhang

µÇ¼ºó¸´ÖÆ

Ö´ÐкóµÄÈÕÖ¾£ºRemoving user hdfs from group san_zhang

°¸Àý 2£º

ͳ¼Æij¸ö·Ö×éÏÂÓÐÄÄЩÓû§

[root@cdh01 ~]# grep hdfs /etc/group hdfs:x:993:

[root@cdh01 ~]# awk -F : ‘{print 4}’ /etc/passwd | grep ‘993’ hdfs 993

10.ÎļþµÄȨÏÞ – ʹÓà “+” ÉèÖÃȨÏÞ£¬Ê¹Óà “-” ÓÃÓÚ×÷·Ï

ls -lh ÏÔʾȨÏÞ ls /tmp | pr -T5 -W$COLUMNS ½«Öն˻®·Ö³É5À¸ÏÔʾ chmod ugo+rwx directory1 ÉèÖÃĿ¼µÄËùÓÐÈË(u)¡¢Èº×é(g)ÒÔ¼°ÆäËûÈË(o)ÒÔ¶Á£¨r £©¡¢Ð´(w)ºÍÖ´ÐÐ(x)µÄȨÏÞ chmod go-rwx directory1 ɾ³ýȺ×é(g)ÓëÆäËûÈË(o)¶ÔĿ¼µÄ¶ÁдִÐÐȨÏÞ chown user1 file1 ¸Ä±äÒ»¸öÎļþµÄËùÓÐÈËÊôÐÔ chown -R user1 directory1 ¸Ä±äÒ»¸öĿ¼µÄËùÓÐÈËÊôÐÔ²¢Í¬Ê±¸Ä±ä¸ÄĿ¼ÏÂËùÓÐÎļþµÄÊôÐÔ chgrp group1 file1 ¸Ä±äÎļþµÄȺ×é chown user1:group1 file1 ¸Ä±äÒ»¸öÎļþµÄËùÓÐÈ˺ÍȺ×éÊôÐÔ find / -perm -u+s ö¾ÙÒ»¸öϵͳÖÐËùÓÐʹÓÃÁËSUID¿ØÖƵÄÎļþ chmod u+s /bin/file1 ÉèÖÃÒ»¸ö¶þ½øÖÆÎļþµÄ SUID λ - ÔËÐиÃÎļþµÄÓû§Ò²±»¸¶ÓëºÍËùÓÐÕßͬÑùµÄȨÏÞ chmod u-s /bin/file1 ½ûÓÃÒ»¸ö¶þ½øÖÆÎļþµÄ SUIDλ chmod g+s /home/public ÉèÖÃÒ»¸öĿ¼µÄSGID λ - ÀàËÆSUID £¬²»¹ýÕâÊÇÕë¶ÔĿ¼µÄ chmod g-s /home/public ½ûÓÃÒ»¸öĿ¼µÄ SGID λ chmod o+t /home/public ÉèÖÃÒ»¸öÎļþµÄ STIKY λ - Ö»ÔÊÐíÕýµ±ËùÓÐÈËɾ³ýÎļþ chmod o-t /home/public ½ûÓÃÒ»¸öĿ¼µÄ STIKY λ

µÇ¼ºó¸´ÖÆ

11.ÎļþµÄÌØÊâÊôÐÔ – ʹÓà “+” ÉèÖÃȨÏÞ£¬Ê¹Óà “-” ÓÃÓÚ×÷·Ï

chattr +a file1 Ö»ÔÊÐíÒÔ×·¼Ó·½·¨¶ÁдÎļþ chattr +c file1 ÔÊÐíÕâ¸öÎļþÄܱ»ÄÚºË×Ô¶¯Ñ¹Ëõ/½âѹ chattr +d file1 ÔÚ¾ÙÐÐÎļþϵͳ±¸·Ýʱ£¬dump³ÌÐò½«ºöÂÔÕâ¸öÎļþ chattr +i file1 ÉèÖóɲ»¿É±äµÄÎļþ£¬²»¿É±»É¾³ý¡¢Ð޸ġ¢ÖØÃüÃû»òÕßÁ´½Ó chattr +s file1 ÔÊÐíÒ»¸öÎļþ±»Çå¾²µØɾ³ý chattr +S file1 Ò»µ©Ó¦ÓóÌÐò¶ÔÕâ¸öÎļþÖ´ÐÐÁËд²Ù×÷£¬Ê¹Ï½µµÍ¢¿Ì°ÑÐ޸ĵÄЧ¹ûдµ½´ÅÅÌ chattr +u file1 ÈôÎļþ±»É¾³ý£¬ÏµÍ³»áÔÊÐíÄãÔÚÒÔºó»Ö¸´Õâ¸ö±»É¾³ýµÄÎļþ lsattr ÏÔʾÌØÊâµÄÊôÐÔ

µÇ¼ºó¸´ÖÆ

12.´ò°üºÍѹËõÎļþ

bunzip2 file1.bz2 ½âѹһ¸ö½Ð×ö 'file1.bz2'µÄÎļþ bzip2 file1 ѹËõÒ»¸ö½Ð×ö 'file1' µÄÎļþ gunzip file1.gz ½âѹһ¸ö½Ð×ö 'file1.gz'µÄÎļþ gzip file1 ѹËõÒ»¸ö½Ð×ö 'file1'µÄÎļþ gzip -9 file1 ×îºéÁ÷ƽѹËõ rar a file1.rar test_file ½¨ÉèÒ»¸ö½Ð×ö 'file1.rar' µÄ°ü rar a file1.rar file1 file2 dir1 ͬʱѹËõ 'file1', 'file2' ÒÔ¼°Ä¿Â¼ 'dir1' unrar x file1.rar ½âѹrar°ü   #ÈôÊÇÎÞunrarÏÂÁ²Î¿¼£ºLinux CentOS 7.0 Ï rar unrarµÄ×°ÖÃtar -cvf archive.tar file1 ½¨ÉèÒ»¸ö·ÇѹËõµÄ tarball tar -cvf archive.tar file1 file2 dir1 ½¨ÉèÒ»¸ö°üÀ¨ÁË 'file1', 'file2' ÒÔ¼° 'dir1'µÄµµ°¸Îļþ tar -tf archive.tar ÏÔʾһ¸ö°üÖеÄÄÚÈÝ tar -xvf archive.tar ÊÍ·ÅÒ»¸ö°ü tar -xvf archive.tar -C /tmp ½«Ñ¹Ëõ°üÊͷŵ½ /tmpĿ¼Ï tar -cvfj archive.tar.bz2 dir1 ½¨ÉèÒ»¸öbzip2ÃûÌõÄѹËõ°ü tar -jxvf archive.tar.bz2 ½âѹһ¸öbzip2ÃûÌõÄѹËõ°ü tar -cvfz archive.tar.gz dir1 ½¨ÉèÒ»¸ögzipÃûÌõÄѹËõ°ü tar -zxvf archive.tar.gz ½âѹһ¸ögzipÃûÌõÄѹËõ°ü zip file1.zip file1 ½¨ÉèÒ»¸özipÃûÌõÄѹËõ°ü zip -r file1.zip file1 file2 dir1 ½«¼¸¸öÎļþºÍĿ¼ͬʱѹËõ³ÉÒ»¸özipÃûÌõÄѹËõ°ü unzip file1.zip ½âѹһ¸özipÃûÌÃѹËõ°ü

µÇ¼ºó¸´ÖÆ

13.OS°ü¹ÜÀíÆ÷

¢Ù¡¢RPM °ü – £¨Fedora, Redhat¼°ÀàËÆϵͳ£©

rpm -ivh package.rpm ×°ÖÃÒ»¸örpm°ü rpm -ivh --nodeps package.rpm ×°ÖÃÒ»¸örpm°ü¶øºöÂÔÒÀÀµ¹ØϵÖÒÑÔ rpm -U package.rpm ¸üÐÂÒ»¸örpm°üµ«²»¸Ä±äÆäÉèÖÃÎļþ rpm -F package.rpm ¸üÐÂÒ»¸öÈ·¶¨ÒѾ­×°ÖõÄrpm°ü rpm -e [--nodeps] package_name.rpm ɾ³ýÒ»¸örpm°ü[--nodepsÌåÏÖºöÂÔÒÀÀµ¹Øϵ] rpm -e --nodeps `rpm -qa | grep clickhouse` ÅúÁ¿É¾³ýËùÓÐ ClickHouse ÒÑ×°ÖÃµÄ rpm °ü,²¢ºöÂÔÏ໥¼äµÄÒÀÀµ¹Øϵrpm -qa ÏÔʾϵͳÖÐËùÓÐÒѾ­×°ÖõÄrpm°ü rpm -qa | grep httpd ÏÔʾËùÖøÃû³ÆÖаüÀ¨ "httpd" ×ÖÑùµÄrpm°ü rpm -qi package_name »ñÈ¡Ò»¸öÒÑ×°ÖðüµÄÌØÊâÐÅÏ¢ rpm -qg "System Environment/Daemons" ÏÔʾһ¸ö×é¼þµÄrpm°ü rpm -ql package_name ÏÔʾһ¸öÒѾ­×°ÖõÄrpm°üÌṩµÄÎļþÁбí rpm -qc package_name ÏÔʾһ¸öÒѾ­×°ÖõÄrpm°üÌṩµÄÉèÖÃÎļþÁбí rpm -q package_name --whatrequires ÏÔʾÓëÒ»¸örpm°ü±£´æÒÀÀµ¹ØϵµÄÁбí rpm -q package_name --whatprovides ÏÔʾһ¸örpm°üËùÕ¼µÄÌå»ý rpm -q package_name --scripts ÏÔʾÔÚ×°ÖÃ/ɾ³ýʱ´úËùÖ´Ðеľ籾l rpm -q package_name --changelog ÏÔʾһ¸örpm°üµÄÐÞ¸ÄÀúÊ· rpm -qf /etc/httpd/conf/httpd.conf È·ÈÏËù¸øµÄÎļþÓÉÄĸörpm°üËùÌṩ rpm -qp package.rpm -l ÏÔʾÓÉÒ»¸öÉÐδװÖõÄrpm°üÌṩµÄÎļþÁбí rpm --import /media/cdrom/RPM-GPG-KEY µ¼È빫ԿÊý×ÖÖ¤Êé rpm --checksig package.rpm È·ÈÏÒ»¸örpm°üµÄÍêÕûÐÔ rpm -qa gpg-pubkey È·ÈÏÒÑ×°ÖõÄËùÓÐrpm°üµÄÍêÕûÐÔ rpm -V package_name ¼ì²éÎļþ³ß´ç¡¢ ÔÊÐí¡¢ÀàÐÍ¡¢ËùÓÐÕß¡¢Èº×é¡¢MD5¼ì²éÒÔ¼°×îºóÐÞ¸Äʱ¼ä rpm -Va ¼ì²éϵͳÖÐËùÓÐÒÑ×°ÖõÄrpm°ü- СÐÄʹÓà rpm -Vp package.rpm È·ÈÏÒ»¸örpm°ü»¹Î´×°Öà rpm2cpio package.rpm | cpio --extract --make-directories *bin* ´ÓÒ»¸örpm°üÔËÐпÉÖ´ÐÐÎļþ rpm -ivh /usr/src/redhat/RPMS/`arch`/package.rpm ´ÓÒ»¸örpmÔ´Âë×°ÖÃÒ»¸ö¹¹½¨ºÃµÄ°ü rpmbuild --rebuild package_name.src.rpm ´ÓÒ»¸örpmÔ´Âë¹¹½¨Ò»¸ö rpm °ü

µÇ¼ºó¸´ÖÆ

¢Ú¡¢YUM Èí¼þ°üÉý¼¶Æ÷ – £¨Fedora, RedHat¼°ÀàËÆϵͳ£©

yum install package_name ÏÂÔز¢×°ÖÃÒ»¸örpm°ü (Èç: yum -y install zip unzip)yum localinstall package_name.rpm ½«×°ÖÃÒ»¸örpm°ü£¬Ê¹ÓÃÄã×Ô¼ºµÄÈí¼þ¿ÍջΪÄã½â¾öËùÓÐÒÀÀµ¹Øϵ yum update package_name.rpm ¸üÐÂÄ¿½ñϵͳÖÐËùÓÐ×°ÖõÄrpm°ü yum update package_name ¸üÐÂÒ»¸örpm°ü yum remove package_name ɾ³ýÒ»¸örpm°ü yum list | grep tmux  ÁгöËùÓпɰ²ÑbµÄÈí¼þÇåµ¥ÏÂÁîyum search package_name ÔÚrpm¿ÍÕ»ÖÐÕ÷²ÉÈí¼þ°ü yum clean packages ÕûÀírpm»º´æɾ³ýÏÂÔصİü yum clean headers ɾ³ýËùÓÐÍ·Îļþ yum clean all ɾ³ýËùÓлº´æµÄ°üºÍÍ·Îļþ

µÇ¼ºó¸´ÖÆ

¢Û¡¢DEB °ü (Debian, Ubuntu ÒÔ¼°ÀàËÆϵͳ)

dpkg -i package.deb ×°ÖÃ/¸üÐÂÒ»¸ö deb °ü dpkg -r package_name ´Óϵͳɾ³ýÒ»¸ö deb °ü dpkg -l ÏÔʾϵͳÖÐËùÓÐÒѾ­×°ÖÃµÄ deb °ü dpkg -l | grep httpd ÏÔʾËùÖøÃû³ÆÖаüÀ¨ "httpd" ×ÖÑùµÄdeb°ü dpkg -s package_name »ñµÃÒѾ­×°ÖÃÔÚϵͳÖÐÒ»¸öÌØÊâ°üµÄÐÅÏ¢ dpkg -L package_name ÏÔʾϵͳÖÐÒѾ­×°ÖõÄÒ»¸ödeb°üËùÌṩµÄÎļþÁбí dpkg --contents package.deb ÏÔʾÉÐδװÖõÄÒ»¸ö°üËùÌṩµÄÎļþÁбí dpkg -S /bin/ping È·ÈÏËù¸øµÄÎļþÓÉÄĸödeb°üÌṩ

µÇ¼ºó¸´ÖÆ

¢Ü¡¢APT Èí¼þ¹¤¾ß (Debian, Ubuntu ÒÔ¼°ÀàËÆϵͳ)

apt-get install package_name ×°ÖÃ/¸üÐÂÒ»¸ö deb °ü apt-cdrom install package_name ´Ó¹âÅÌ×°ÖÃ/¸üÐÂÒ»¸ö deb °ü apt-get update Éý¼¶ÁбíÖеÄÈí¼þ°ü apt-get upgrade Éý¼¶ËùÓÐÒÑ×°ÖõÄÈí¼þ apt-get remove package_name ´Óϵͳɾ³ýÒ»¸ödeb°ü apt-get check È·ÈÏÒÀÀµµÄÈí¼þ¿Íջ׼ȷ apt-get clean ´ÓÏÂÔصÄÈí¼þ°üÖÐÕûÀí»º´æ apt-cache search searched-package ·µ»Ø°üÀ¨ËùÒªËÑË÷×Ö·û´®µÄÈí¼þ°üÃû³Æ

µÇ¼ºó¸´ÖÆ

14.Îı¾Éó²é¡¢´¦Àí

¢Ù¡¢Éó²éÎļþÄÚÈÝ

cat file1 ´ÓµÚÒ»¸ö×Ö½Ú×îÏÈÕýÏòÉó²éÎļþµÄÄÚÈÝ tac file1 ´Ó×îºóÒ»ÐÐ×îÏÈ·´ÏòÉó²éÒ»¸öÎļþµÄÄÚÈÝ more file1 Éó²éÒ»¸ö³¤ÎļþµÄÄÚÈÝ less file1 ÀàËÆÓÚ 'more' ÏÂÁ¿ÉÊÇËüÔÊÐíÔÚÎļþÖкÍÕýÏò²Ù×÷Ò»ÑùµÄ·´Ïò²Ù×÷ head -2 file1 Éó²éÒ»¸öÎļþµÄÇ°Á½ÐÐ tail -2 file1 Éó²éÒ»¸öÎļþµÄ×îºóÁ½ÐÐ tail -f /var/log/messages ʵʱÉó²é±»Ìí¼Óµ½Ò»¸öÎļþÖеÄÄÚÈÝ

µÇ¼ºó¸´ÖÆ

¢Ú¡¢Îı¾´¦Àí

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 ºÏ²¢Ò»¸öÎļþµÄÏêϸ˵Ã÷Îı¾£¬²¢½«¼ò½éдÈëÒ»¸öÐÂÎļþÖÐ cat file1 | command( sed, grep, awk, grep, etc...) >> result.txt ºÏ²¢Ò»¸öÎļþµÄÏêϸ˵Ã÷Îı¾£¬²¢½«¼ò½éдÈëÒ»¸öÒÑÓеÄÎļþÖÐ grep Aug /var/log/messages ÔÚÎļþ '/var/log/messages'ÖвéÕÒÒªº¦´Ê"Aug" grep ^Aug /var/log/messages ÔÚÎļþ '/var/log/messages'ÖвéÕÒÒÔ"Aug"×îÏȵĴʻã grep [0-9] /var/log/messages Ñ¡Ôñ '/var/log/messages' ÎļþÖÐËùÓаüÀ¨Êý×ÖµÄÐÐ grep Aug -R /var/log/* ÔÚĿ¼ '/var/log' ¼°ËæºóµÄĿ¼ÖÐËÑË÷×Ö·û´®"Aug" grep -E 'string_1|string_2' /var/log/test.log ÔÚÈÕÖ¾ÖÐͬʱÅÌÎÊ°üÀ¨ string_1»ò°üÀ¨string_2µÄ¼Í¼# Æ¥ÅäredisÖÐ, field ÖаüÀ¨ÒÔ1µ½4λÊý×Ö¿ªÍ·,ÒÔ"_ÒÑϵ¥"×îºóµÄ×Ö·û, ²¢½«Æä value Öµ´ø³öÀ´(-A1)redis-cli -h 111.111.111.111 -p 7001 -c -a ${PASSWORD} --raw hgetall 2022-03-24_ORDER_STAT | grep -E "^[[:digit:]]{1,4}_ÒÑϵ¥" -A1grep -Hnr docker * ÔÚ±¾²ã»ò×ÓÎļþ¼ÐÀïµÝ¹é²éÕÒ°üÀ¨Ö¸¶¨×Ö·û¡°docker¡±µÄÎļþ£¬²¢ÏÔʾÎļþÃû+ÐкÅ£¬ÈôÊÇ׼ȷƥÅäÎı¾£¬¼Óo²ÎÊý¡£²ÎÊý¼ÄÒ壺£¨H£ÔÃÄ¿ÎÆ¥Åäʱ½«ÎļþÃû´òÓ¡³öÀ´£»n£º´òÓ¡×Ö·û´®ËùÔÚµÄÐкÅ£»r£ºµÝ¹é²éÕÒ£»o£º×¼È·Æ¥Åäµ½µ¥´Ê£¬¶àÒ»¸ö×Ö·û¶¼²»¿É£©

µÇ¼ºó¸´ÖÆ

¡°grepÏÔʾƥÅäÐеÄÉÏÏÂÐÐÄÚÈÝ¡±×¨Ì⣺

grep -A2 2 test.txt  ·µ»ØÆ¥ÅäÐкÍÆ¥ÅäÐеĺóÁ½ÐÐ grep -B2 2 test.txt  ·µ»ØÆ¥ÅäÐкÍÆ¥ÅäÐеÄÇ°Á½ÐÐ grep -C2 2 text.txt »òÕß grep -A2 -B2 2 test.txt ·µ»ØÆ¥ÅäÐкÍÆ¥ÅäÐеÄÇ°ºóÁ½ÐÐ

µÇ¼ºó¸´ÖÆ

-A -B -C ºóÃæ¸ú°¢À­²®Êý×Ö

-A ·µ»ØÆ¥ÅäºóºÍËüºóÃæµÄnÐÐ,(After£¬Ö®ºó) ¡£

-B ·µ»ØÆ¥ÅäÐкÍËüÇ°ÃæµÄnÐÐ,(Before£¬Ö®Ç°) ¡£

-C ·µ»ØÆ¥ÅäÐкÍËüÇ°ºó¸÷nÐУ¬Í¨-AºÍ-BÁªÓÃ,(Context£¬ÉÏÏÂÎļ´Ç°ºó) ¡£

Å£±Æ°¡£¡½Ó˽»î±Ø±¸µÄ N ¸ö¿ªÔ´ÏîÄ¿£¡¸ÏæÕä²Ø

µÇ¼ºó¸´ÖÆ

sed -i 's/string1/string2/g' example.txt ½«example.txtÎļþÖÐµÄ "string1" Ìæ»»³É "string2"(ÈôÊDz»¼Ó-i²ÎÊý,ÔòÔÚÄÚ´æÖÐÌæ»»; Ìí¼Ó-i²ÎÊý,ÔòÔÚÎļþÖÐÖ±½ÓÌæ»»)sed '/^$/d' example.txt ´Óexample.txtÎļþÖÐɾ³ýËùÓпÕȱÐÐ sed '/ *#/d; /^$/d' example.txt ´Óexample.txtÎļþÖÐɾ³ýËùÓÐ×¢ÊͺͿÕȱÐÐ echo 'hElloWorld' | tr '[:lower:]' '[:upper:]' ÕÒ³öËùÓеÄСд×Öĸ²¢ËùÓÐÌ滻Ϊ´óд×Öĸ sed -e '1d' result.txt ´ÓÎļþexample.txt ÖÐɨ³ýµÚÒ»ÐÐ sed -n '/string1/p' Éó²éÖ»°üÀ¨´Ê»ã "string1"µÄÐÐ sed -e 's/ *$//' example.txt ɾ³ýÿһÐÐ×îºóµÄ¿Õȱ×Ö·û sed -e 's/string1//g' example.txt ´ÓÎĵµÖÐֻɾ³ý´Ê»ã "string1" ²¢±£´æÊ£ÓàËùÓÐ sed -n '1,5p;5q' example.txt Éó²é´ÓµÚÒ»Ðе½µÚ5ÐÐÄÚÈÝ sed -n '5p;5q' example.txt Éó²éµÚ5ÐÐ sed -e 's/00*/0/g' example.txt Óõ¥¸öÁãÌæ»»¶à¸öÁãsed -i '3i helloword' test.txt   ÔÚtest.txtÎļþµÄµÚÈýÐвåÈë¡®helloword¡¯×Ö·û´®

µÇ¼ºó¸´ÖÆ

¡°sed°´Ö¸¶¨×Ö·û´®É¾³ý¡±×¨Ì⣺

ÓÃsedɾ³ýÆ¥Åäµ½×Ö·û´®µÄÐУº

Óï·¨£ºsed-i’/Òªº¦×Ö·û/d’ÎļþÃû

¾ÙÀý1£ºÆ¥Åä”\etc\install.sh”

sed -i '/\/etc\/install.sh/d' 1.txt

µÇ¼ºó¸´ÖÆ

-i ÌåÏÖ²Ù×÷ÔÚÔ´ÎļþÉÏÉúЧ.²»È»²Ù×÷ÄÚ´æÖÐÊý¾Ý,²¢²»Ð´ÈëÎļþÖÐ. ÔÚ·ÖºÅÄÚµÄ/dÌåÏÖɾ³ýÆ¥ÅäµÄÐÐ ¡£

¾ÙÀý2£ºÉ¾³ýÒÔa¿ªÍ·µÄÐÐ

sed -i '/^a.*/d' tmp.txt

µÇ¼ºó¸´ÖÆ

^aÌåÏÖ¿ªÍ·ÊÇa, .*ÌåÏÖºó¸úí§Òâ×Ö·û´®

Example-1: ʹÓÃsed¾ÙÐÐÎı¾ÅúÁ¿Ìæ»»

#!/bin/bash ddl_file_path=/c/Users/user/Downloads/sqoop_data/hive_2_mysql  ls $ddl_file_path | while read f;doecho "--------->"$ddl_file_path/$f ## Template#sed -i 's///g' $ddl_file_path/$f#sed -i "s///g" $ddl_file_path/$f sed -i 's/111.111.111.111:3306/222.222.222.222:3307/g' $ddl_file_path/$fsed -i "s/'password_1'/'password_2'/g" $ddl_file_path/$f done # echo -e "=========>\n\t Files contains keyword "/WARN:" in path $ddl_file_path are deleted!!!"

µÇ¼ºó¸´ÖÆ

#!/bin/bash set -x ## Template#sed -i 's///g' $ddl_file_path/$f#sed -i "s///g" $ddl_file_path/$f ## Func 1 - ʵÏÖÔÚËùÓÐÎļþµÄµÚËÄÐС¢µÚÎåÐвåÈëÖ¸¶¨Îı¾ ddl_file_path=/e/ѸÀ×ÏÂÔØ/user_data_after ls $ddl_file_path | while read f;do        # ÈôÊÇÎļþ²»ÊÇÎļþ¼ÐÀàÐÍ£¬²ÅÔÊÐí²åÈë²Ù×÷    if [ ! -d $f ];then        echo "--------->"$ddl_file_path/$f         sed -i '4i retries=10' $ddl_file_path/$f        sed -i '5i retry.backoff=3' $ddl_file_path/$f    fidone  ## Func 2 - ÈôÊÇÎļþ¼Ð²»±£´æ£¬Ôò½¨É裻·´Ö®ÌáÐÑÎļþÒѱ£´æ if [ ! -d "beijing" ];then    mkdir beijingelse    echo "File already exists"fi

µÇ¼ºó¸´ÖÆ

ÎļþÀàÐ͵IJÎÊýÅбð´óÈ«£º

shell¾ç±¾ÅжÏÎļþÀàÐÍ shellÅжÏÎļþ,Ŀ¼ÊÇ·ñ±£´æ»òÕß¾ßÓÐȨÏÞ #!/bin/sh  myPath="/var/log/httpd/" myFile="/var/log/httpd/access.log"  # ÕâÀïµÄ-x ²ÎÊýÅжÏ$myPathÊÇ·ñ±£´æ²¢ÇÒÊÇ·ñ¾ßÓпÉÖ´ÐÐȨÏÞ if [ ! -x "$myPath"]; then mkdir "$myPath"  fi   # ÕâÀïµÄ-d ²ÎÊýÅжÏ$myPathÊÇ·ñ±£´æ  if [ ! -d "$myPath"]; then  mkdir "$myPath"  fi   # ÕâÀïµÄ-f²ÎÊýÅжÏ$myFileÊÇ·ñ±£´æ  if [ ! -f "$myFile" ]; then  touch "$myFile"  fi   # ÆäËû²ÎÊýÉÐÓÐ-n,-nÊÇÅжÏÒ»¸ö±äÁ¿ÊÇ·ñÊÇ·ñÓÐÖµ  if [ ! -n "$myVar" ]; then  echo "$myVar is empty"  exit 0  fi   # Á½¸ö±äÁ¿ÅжÏÊÇ·ñÏàµÈ  if [ "$var1" = "$var2" ]; then  echo '$var1 eq $var2'  else  echo '$var1 not eq $var2'  fi

µÇ¼ºó¸´ÖÆ

ÎļþµÄÅбðÂß¼­´óÈ«£º

-a file exists. -b file exists and is a block special file. -c file exists and is a character special file. -d file exists and is a directory. -e file exists (just the same as -a). -f file exists and is a regular file. -g file exists and has its setgid(2) bit set. -G file exists and has the same group ID as this process. -k file exists and has its sticky bit set. -L file exists and is a symbolic link. -n string length is not zero. -o Named option is set on. -O file exists and is owned by the user ID of this process. -p file exists and is a first in, first out (FIFO) special file or named pipe. -r file exists and is readable by the current process. -s file exists and has a size greater than zero. -S file exists and is a socket. -t file descriptor number fildes is open and associated with a terminal device. -u file exists and has its setuid(2) bit set. -w file exists and is writable by the current process. -x file exists and is executable by the current process. -z string length is zero.  ×¢ÖØ-s ºÍ -f ²ÎÊýµÄÇø±ð

µÇ¼ºó¸´ÖÆ

cat -n file1 ±êʾÎļþµÄÐÐÊý cat example.txt | awk 'NR%2==1' ɾ³ýexample.txtÎļþÖеÄËùÓÐżÊýÐÐ echo a b c | awk '{print $1}' Éó²éÒ»ÐеÚÒ»À¸ echo a b c | awk '{print $1,$3}' Éó²éÒ»ÐеĵÚÒ»ºÍµÚÈýÀ¸ paste file1 file2 ºÏ²¢Á½¸öÎļþ»òÁ½À¸µÄÄÚÈÝ paste -d '+' file1 file2 ºÏ²¢Á½¸öÎļþ»òÁ½À¸µÄÄÚÈÝ£¬ÖÐÑëÓÃ"+"Çø·Ö sort file1 file2 ÅÅÐòÁ½¸öÎļþµÄÄÚÈÝ sort file1 file2 | uniq È¡³öÁ½¸öÎļþµÄ²¢¼¯(Öظ´µÄÐÐÖ»±£´æÒ»·Ý) sort file1 file2 | uniq -u ɾ³ý½»¼¯£¬ÁôÏÂÆäËûµÄÐÐ sort file1 file2 | uniq -d È¡³öÁ½¸öÎļþµÄ½»¼¯(Ö»ÁôÏÂͬʱ±£´æÓÚÁ½¸öÎļþÖеÄÎļþ) comm -1 file1 file2 ½ÏÁ¿Á½¸öÎļþµÄÄÚÈÝֻɾ³ý 'file1' Ëù°üÀ¨µÄÄÚÈÝ comm -2 file1 file2 ½ÏÁ¿Á½¸öÎļþµÄÄÚÈÝֻɾ³ý 'file2' Ëù°üÀ¨µÄÄÚÈÝ comm -3 file1 file2 ½ÏÁ¿Á½¸öÎļþµÄÄÚÈÝֻɾ³ýÁ½¸öÎļþ¹²ÓеIJ¿·Ö

µÇ¼ºó¸´ÖÆ

×ۺϰ¸Àý:

¢Ù£º±¾»útcpÖÖÖÖ״̬Êýͳ¼Æ

netstat -n | awk '/^tcp/ {++S[$NF]} END {for(a in S) print a, S[a]}'CLOSE_WAIT 2ESTABLISHED 276SYN_SENT 2TIME_WAIT 63270

µÇ¼ºó¸´ÖÆ

awk ‘BEGIN { sum = 0; for (i = 0; i < 20; ++i) { sum += i; if (sum > 50) exit(10); else print “Sum =”, sum } }’

¢Ú£ºÊ¹ÓÃcutÌáÈ¡Îı¾×Ö·û´®£º

°´¡°:¡±Ö§½â£¬ÌáÈ¡/etc/passwdÖеÚ1,3,4,5ÁÐÊý¾Ý£¬°´Ô­ÍÑÀë·û”:”¾ÙÐÐÆ´½Ó ¡£

[hdfs@cdh01 test]$ head -n 5 /etc/passwd | cut -d : -f 1,3-5root:0:0:rootbin:1:1:bindaemon:2:2:daemonadm:3:4:admxixi:4:7:xixi

µÇ¼ºó¸´ÖÆ

¢Û£ºÊ¹ÓÃuniq¾ÙÐÐÂËÖØ

cutµÄÏêϸÓ÷¨£¬ÈçÏ£º

A).È¥³ýÖظ´ÐÐ

sort target_file | uniq

µÇ¼ºó¸´ÖÆ

B).²éÕÒ·ÇÖظ´ÐÐ

sort target_file | uniq -u

µÇ¼ºó¸´ÖÆ

C).²éÕÒÖظ´ÐÐ

sort target_file | uniq -d

µÇ¼ºó¸´ÖÆ

D).ͳ¼Æÿһ¸öÎļþ·ºÆðµÄ´ÎÊý

sort target_file | uniq -c

µÇ¼ºó¸´ÖÆ

¢Ü£ºÅÅÐò

sort linuxϵÄÅÅÐò¹¤¾ß

²ÎÊý˵Ã÷:

-r¡¡¡¡½µÐòÅÅÁÐ

-u¡¡¡¡È¥ÖØ

-n¡¡¡¡ÒÔÊý×Ö¾ÞϸÅÅÐò(ĬÈÏÊÇÊ××ÖĸÅÅÐò)

-t¡¡¡¡Ö¸¶¨ÍÑÀë·û ÕâÀïÎÒÃÇÖ¸¶¨’|’ΪÍÑÀë·û

-k¡¡¡¡Ö¸¶¨ÍÑÀëºóµÄµÚ¼¸Î»¾ÙÐÐÅÅÐò ÕâÀïÎÒÃÇÖ¸¶¨µÚ2λ

ʹÃü:report.txtÎļþÀïÓÐÒÔÏÂÄÚÈÝ£º¼Í¼ÁËһЩҪÁìµÄÖ´ÐÐʱ¼ä£¬ÒªÇó°´Ö´ÐÐʱ¼ä½µÐòÅÅÁÐ.

ÏÂÁsort -run -k 2 -t ‘|’ report.txt

 1 void com.dustpan.zeus.core.service.MergeService.startService(int)|2 2 void com.dustpan.zeus.core.service.InitShopDateService.startService(int)|1 3 boolean com.dustpan.zeus.core.service.MergeService.executeGePrintSyncTask()|475 4 boolean com.dustpan.zeus.core.service.InitShopDateService.executeInitShopTask()|96 5 boolean com.dustpan.zeus.core.service.MergeService.executeGePrintSyncTask()|1013 6 boolean com.dustpan.zeus.core.service.InitShopDateService.executeInitShopTask()|184 7 boolean com.dustpan.zeus.core.service.MergeService.executeGePrintSyncTask()|729 8 boolean com.dustpan.zeus.core.service.InitShopDateService.executeInitShopTask()|14 9 boolean com.dustpan.zeus.core.service.MergeService.executeGePrintSyncTask()|39410 boolean com.dustpan.zeus.core.service.InitShopDateService.executeInitShopTask()|9011 boolean com.dustpan.zeus.core.service.MergeService.executeGePrintSyncTask()|56912 boolean com.dustpan.zeus.core.service.InitShopDateService.executeInitShopTask()|79613 boolean com.dustpan.zeus.core.service.MergeService.executeGePrintSyncTask()|164814 boolean com.dustpan.zeus.core.service.InitShopDateService.executeInitShopTask()|8215 boolean com.dustpan.zeus.core.service.MergeService.executeGePrintSyncTask()|101816 boolean com.dustpan.zeus.core.service.InitShopDateService.executeInitShopTask()|1417 boolean com.dustpan.zeus.core.service.MergeService.executeGePrintSyncTask()|93718 boolean com.dustpan.zeus.core.service.InitShopDateService.executeInitShopTask()|1719 boolean com.dustpan.zeus.core.service.MergeService.executeGePrintSyncTask()|60120 boolean com.dustpan.zeus.core.service.InitShopDateService.executeInitShopTask()|5221 boolean com.dustpan.zeus.core.service.MergeService.executeGePrintSyncTask()|508122 boolean com.dustpan.zeus.core.service.InitShopDateService.executeInitShopTask()|38823 boolean com.dustpan.zeus.core.service.MergeService.executeGePrintSyncTask()|19824 boolean com.dustpan.zeus.core.service.InitShopDateService.executeInitShopTask()|1125 boolean com.dustpan.zeus.core.service.MergeService.executeGePrintSyncTask()|20326 boolean com.dustpan.zeus.core.service.InitShopDateService.executeInitShopTask()|1127 boolean com.dustpan.zeus.core.service.MergeService.executeGePrintSyncTask()|24128 boolean com.dustpan.zeus.core.service.InitShopDateService.executeInitShopTask()|1329 boolean com.dustpan.zeus.core.service.MergeService.executeGePrintSyncTask()|17630 boolean com.dustpan.zeus.core.service.InitShopDateService.executeInitShopTask()|1231 boolean com.dustpan.zeus.core.service.MergeService.executeGePrintSyncTask()|20632 boolean com.dustpan.zeus.core.service.InitShopDateService.executeInitShopTask()|3333 boolean com.dustpan.zeus.core.service.MergeService.executeGePrintSyncTask()|24234 boolean com.dustpan.zeus.core.service.InitShopDateService.executeInitShopTask()|19

µÇ¼ºó¸´ÖÆ

°¸ÀýÒ»¡¢ÕÒ³ö±¾Îļþ¼ÐÖаüÀ¨my_test_calendarÒªº¦×ÖµÄËùÓÐÎļþ(º¬È«Â·¾¶+ÎļþÃû)£¬²¢ÂËÖØ ¡£

ÅÌÎÊhive_shĿ¼Ï£¬°üÀ¨ËÑË÷Òªº¦×Ö’my_test_calendar’µÄÎı¾·ºÆðµÄÎļþ¼°Òªº¦×ÖËùÔÚµÄÐУ¬½«Îļþ(Îļþ·¾¶+ÎļþÃû) ×Ö¶ÎÌáÈ¡³öÀ´£¬²¢×öÂËÖØ´¦Àí ¡£

[hdfs@nn1 hive_sh]$ find . -type f | xargs grep -rn 'my_test_calendar' | cut -d : -f 1 | uniq

µÇ¼ºó¸´ÖÆ

°¸Àý¶þ¡¢²éÕÒËùÓзºÆðÖ¸¶¨Îı¾µÄÎļþ²¢ÂËÖØ£¨½ø½×°æ£©

¾ç±¾ËµÃ÷:

±éÀú hive_tables.txt ÎļþÖеÄËùÓÐ±í£¨Èç hive_table_1£©,²éÕÒÆäÔÚÖ¸¶¨Ä¿Â¼/data/program/hive_sh/ϵÄÎļþÖУ¬ÊÇ·ñʹÓõ½ ¡£ÈôÊDz鵽Öظ´·ºÆð¸ÃÎı¾µÄÎļþ£¬×öÂËÖØ´¦Àí ¡£

cat query_table_usage_in_hive.sh

#!/bin/bash while read tbldo echo ------------------Handle table: $tbl--------------find /data/program/hive_sh/ -type f | xargs grep -rn $tbl | cut -d : -f 1 | uniq > ./output/${tbl}_result.txt done < hive_tables.txt

µÇ¼ºó¸´ÖÆ

°¸ÀýÈý¡¢²éÕÒÄÚ´æºÄÓÃtop3µÄapp

ps auxw | head -1;ps auxw|sort -rn -k4|head -5

µÇ¼ºó¸´ÖÆ

ÒÔÉϾÍÊÇ×îÈ«LinuxÏÂÁî´óÈ«£¬½¨ÒéÕä²Ø£ ¡£ ¡£¡µÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡

ÃâÔð˵Ã÷£ºÒÔÉÏչʾÄÚÈÝȪԴÓÚÏàÖúýÌå¡¢ÆóÒµ»ú¹¹¡¢ÍøÓÑÌṩ»òÍøÂçÍøÂçÕûÀí£¬°æȨÕùÒéÓë±¾Õ¾Î޹أ¬ÎÄÕÂÉæ¼°¿´·¨Óë¿´·¨²»´ú±í×ðÁú¿­Ê±¹ÙÍøµÇ¼ÂËÓÍ»úÍø¹Ù·½Ì¬¶È£¬Çë¶ÁÕß½ö×ö²Î¿¼ ¡£±¾ÎĽӴýתÔØ£¬×ªÔØÇë˵Ã÷À´ÓÉ ¡£ÈôÄúÒÔΪ±¾ÎÄÇÖÕ¼ÁËÄúµÄ°æȨÐÅÏ¢£¬»òÄú·¢Ã÷¸ÃÄÚÈÝÓÐÈκÎÉæ¼°ÓÐÎ¥¹«µÂ¡¢Ã°·¸Ö´·¨µÈÎ¥·¨ÐÅÏ¢£¬ÇëÄúÁ¬Ã¦ÁªÏµ×ðÁú¿­Ê±¹ÙÍøµÇ¼ʵʱÐÞÕý»òɾ³ý ¡£

Ïà¹ØÐÂÎÅ

ÁªÏµ×ðÁú¿­Ê±¹ÙÍøµÇ¼

18523999891

¿É΢ÐÅÔÚÏß×Éѯ

ÊÂÇéʱ¼ä£ºÖÜÒ»ÖÁÖÜÎ壬9:30-18:30£¬½ÚãåÈÕÐÝÏ¢

QR code
ÍøÕ¾µØͼ