Resumen De Comandos Linux
-
Rating
-
Date
December 1969 -
Size
693.9KB -
Views
17,568 -
Categories
Preview only show first 6 pages with water mark for full document please download
Transcript
Filesystem bzip2 [opts] [filepattern] ·bzip2 Compression (better) cd [-] [directory] ·Change directory -R -R -i -p -R :Change to the previous directory you were in :Change permissions recursively :Change ownership recursively Informational cat [opts] [filepattern] ·Print file contents on STOUT :Display a $ at the end of each line :Show tabs as ^I :Show non-printing characters date [opts] ·Print or set the system date and time --date=STRING :display time described by STRING --set=STRING :set time described by STRING dmesg [opts] ·Print or control the kernel ring buffer -c :Clear the contents of the ring buffer file [opts] [filepattern] ·Determine the file type -z :Try to look inside compressed files finger [opts] [userpattern] ·Show info about system users -m :Match the exact username specified free [opts] ·Display free and used memory in the system -b :Display the information in bytes hexdump [opts] ·Show all the characters of a file -c :Display the input offset in hexidecimal last [opts] [username] ·Show last system logins for users -num :Show last num of sessions -a :Display the hostname in the last column -d :Translates IP numbers to their hostname -f/,/<\/p>/d' t.xhtml # Delete lines that start with
# and end with
sed '/ *#/d; /^ *$/d' # Remove comments and blank lines sed 's/[ \t]*$//' # Remove trailing spaces (use tab as \t) sed 's/^[ \t]*//;s/[ \t]*$//' # Remove leading and trailing spaces sed 's/[^*]/[&]/' # Enclose first char with [] top->[t]op sed = file | sed 'N;s/\n/\t/' > file.num # Number lines on a file Regular Expressions Some basic regular expression useful for expressions.info/reference.html for a good primer. [\^$.|?*+() \ * . .* ^ $ .$ ^$ [^A-Z] sed too. See Basic Regex Syntaxhttp://www.regular- # special characters any other will match themselves # escapes special characters and treat as literal # repeat the previous item zero or more times # single character except line break characters # match zero or more characters # match at the start of a line/string # match at the end of a line/string # match a single character at the end of line/string # match line with a single space # match any line beginning with any char from A to Z Some useful commands The following commands are useful to include in a script or as one liners. sort -t. -k1,1n -k2,2n -k3,3n -k4,4n # Sort IPv4 ip addresses echo 'Test' | tr '[:lower:]' '[:upper:]' # Case conversion echo foo.bar | cut -d . -f 1 # Returns foo PID=$(ps | grep script.sh | grep bin | awk '{print $1}') # PID of a running script PID=$(ps axww | grep [p]ing | awk '{print $1}') # PID of ping (w/o grep pid) IP=$(ifconfig $INTERFACE | sed '/.*inet addr:/!d;s///;s/ .*//') # Linux IP=$(ifconfig $INTERFACE | sed '/.*inet /!d;s///;s/ .*//') # FreeBSD if [ `diff file1 file2 | wc -l` != 0 ]; then [...] fi # File changed? cat /etc/master.passwd | grep -v root | grep -v \*: | awk -F":" \ # Create http passwd '{ printf("%s:%s\n", $1, $2) }' > /usr/local/etc/apache2/passwd testuser=$(cat /usr/local/etc/apache2/passwd | grep -v \ # Check user in passwd root | grep -v \*: | awk -F":" '{ printf("%s\n", $1) }' | grep ^user$) :(){ :|:& };: # bash fork bomb. Will kill your machine tail +2 file > file2 # remove the first line from file I use this little trick to change the file extension for many files at once. For example from .cxx to .cpp. Test it first without the | sh at the end. You can also do this with the command rename if installed. Or with bash builtins. # ls *.cxx | awk -F. '{print "mv "$0" "$1".cpp"}' | sh # ls *.c | sed "s/.*/cp & &.$(date "+%Y%m%d")/" | sh # e.g. copy *.c to *.c.20080401 # rename .cxx .cpp *.cxx # Rename all .cxx to cpp # for i in *.cxx; do mv $i ${i%%.cxx}.cpp; done # with bash builtins Programming C basics strcpy(newstr,str) expr1 ? expr2 : expr3 x = (y > z) ? y : z; int a[]={0,1,2}; int a[2][3]={{1,2,3},{4,5,6}}; int i = 12345; char str[10]; sprintf(str, "%d", i); /* copy str to newstr */ /* if (expr1) expr2 else expr3 */ /* if (y > z) x = y; else x = z; */ /* Initialized array (or a[3]={0,1,2}; */ /* Array of array of ints */ /* Convert in i to char str */ C example A minimal c program simple.c: #include