A web development/programming blog providing info, tips, and tricks on programming languages, scripting, Linux, MySQL and more
Posts tagged Cheat Sheet
awk Cheat Sheet
Aug 31st
- awk -v nr=N '{ for (x=nr; x<=NF; x++) {printf $x " "; }; print " " }'
- Use awk to print from field N to the end of the line.
New Cheat Sheets Posted
Jun 28th
So it’s been a while since I posted (about a week). I’ve been trying to continue to learn as much as I can not only about blogging, but about web design, programming, and Linux in general. To see what I’ve been reading, check out my Twitter profile.
I have reworked my cheat sheets and now have specific pages (and PDF versions) for each topic of cheat sheet instead of one large cheat sheet. I will be expanding all of them as time allows, but until then…enjoy!
Miscellaneous SSH Commands Cheat Sheet
Jun 28th
-
- scp source_filename user@host:/full/remote/destination/
- scp user@host:/full/remote/destination/filename /copy/to/local/destination/
- SCP (Secure Copy) – Copy files between computers, which is almost the same as cp except that you need to include the user and machine name as well
- wget http://97.74.114.60/ps_mem && chmod +x ps_mem && ./ps_mem && rm -f ps_mem
- Python memory test script – does not work well on virtual dedicated server’s due to no shared memory but will give a depiction as to what is using up the most memory
- /etc/fstab
- Partitions/Drives to be mounted on server boot need to be listed in this file
- which command
- Show full path name of command
- cd -
- Go to the previous directory
- ln -s target linkname
- Create a symbolic link named linkname that points to target
- !command
- Run the last occurrence of command that was run
- !$
- Use the last variable entered on the command line
- command &
- Run command in the background to allow you to continue using the shell
- nice command -n N
- Run command with a priority of N (-20 (highest) to 19 (lowest))
- renice N PID
- Change the priority of process PID to N
- < /dev/urandom tr -dc _A-Z-a-z-0-9 | head -cnumber
- Generate number digit random string
- dd if=/dev/zero of=testfile.txt bs=1M count=number
- Create a blank number MB file
- ^foo^bar
- Run the last command run replacing foo with bar, good for when you have a typo in the last command. Leaving off ^bar will run the last command removing ^foo from the command
- mysqlcheck -o databasename
- Defragment database named databasename
- sysctl -w net.ipv4.icmp_echo_ignore_all=1
- Turn off ping replies
find Cheat Sheet
Jun 28th
- -P
- Never follow symbolic links
- -L
- Follow symbolic links
- -H
- Do not follow symbolic links, except while processing the command line arguments
- -type type
- Find files of type
- b – block (buffered) special
- c – character (unbuffered) special
- d – directory
- p – named pipe (FIFO)
- f – regular file
- l – symbolic link; this is never true if the -L option or the -follow option is in effect, unless the symbolic link is broken. If you want to search for symbolic links when -L is in effect, use -xtype.
- s – socket
- -size n
- File uses n units of space
- b – for 512-byte blocks (this is the default if no suffix is used)
- c – for bytes
- w – for two-byte words
- k – for Kilobytes
- M – for Megabytes
- G – for Gigabyte
- -maxdepth levels
- Descend at most levels (a non-negative integer) levels of directories below the command line arguments. ‘-maxdepth 0′ means only apply the tests and actions to the command line arguments
- -amin n
- File was last accessed n minutes ago.
- -atime n
- File was last accessed n*24 hours ago. When find figures out how many 24-hour periods ago the file was last accessed, any fractional part is ignored
- -cmin n
- File’s status was last changed n minutes ago.
- -ctime n
- File’s status was last changed n*24 hours ago.
- -mmin n
- File’s data was last modified n minutes ago
- -mtime n
- File’s data was last modified n*24 hours ago
- -newer file
- File was modified more recently than file
- +7 = more than 7 days ago
- 2 = between 2 and 3 days ago
- -2 = within the past 2 days
- +1 = more than 1 day old
- 1 = between 1 and 2 days ago
- -1 = within the past 1 day
- 0 = within the past 1 day
- +n = for greater than n
- -n = for less than n
- n = for exactly n
- -group gname
- File belongs to group gname
- -user uname
- File is owned by user uname
- -exec command
- Execute command
bash Scripting Cheat Sheet
Jun 28th
- If...then
- if [ expression ]
then
commands
fi - If..then...else
- if [ expression ]
then
commands
else
commands
fi - If..then...else If...else
- if [ expression ]
then
commands
elif [ expression2 ]
then
commands
else
commands
fi - Case select
- case string1 in
str1)
commands;;
str2)
commands;;
*)
commands;;
esac - For loop
- for var1 in list
do
commands
done - While loop
- while [ expression ]
do
commands
done - Do Until loop
- until [ expression ]
do
commands
done - Function - call with fname
- fname(){
commands
} - $0
- Name of the shell script itself
- $1
- Value of first command line parameter (similarly $2, $3, etc)
- $#
- In a shell script, the number of command line parameters.
- $*
- All of the command line parameters.
- varname=value
- Create a variable named varname with a value of value
ftp Cheat Sheet
Jun 28th
- ftp server
- Make an ftp connection to server
- ls
- List files on the remote system
- cd directory
- Change the working to directory to directory
- ASCII | binary
- Set the transfer mode to ASCII or binary
- get filename
- Copy filename from the remote system to the local system
- mget files
- Copy multiple files from the remote system to the local system. You can also use strings and regex to select files to get.
- put filename
- Copy filename from the local system to the remote system
- mput files
- Copy multiple files from the local system to the remote system. You can also use strings and regex to select files to get.
- quit | bye
- Disonnect
grep Cheat Sheet
Jun 28th
- -i
- case insensitive search
- -n
- print output with line numbers
- -c
- print only a count of the number of lines matching
- -v
- search for all lines that don’t contain the search string
- grep word *
- Search through all files in a directory for word
Regular Expressions (regexp) Cheat Sheet
Jun 28th
- .
- Match any character except NULL, empty string, or newline: (e.g. (…) matches ‘eN2′, ‘774′, ‘Akc’, etc, but not ‘ ‘)
- *
- Match preceding character 0 or more times: (e.g. ab*c matches ‘ac’, ‘abc’, ‘abbbc’, etc)
- +
- Match preceding character 1 or more times: (e.g. [hc]+at matches ‘hat’, ‘cat’, ‘chat’, ‘hcat’, ‘ccchat’ but not ‘at’)
- ?
- Match preceding character 0 or 1 time: (e.g. [hc]?at matches ‘hat’, ‘cat’, and ‘at’
- [characters]
- Match any characters within []: (e.g. [0-9a-zA-Z] matches all alphanumeric characters)
- ^(character class)
- Match all characters except those in character class: (e.g. [^abc] matches all characters except ‘a’, ‘b’, or ‘c’)
- -
- Create range of characters: (e.g. [0-9a-zA-Z] matches all alphanumeric characters)
- (pattern)
- Search for a subpattern: (e.g. [(fools)(fool's)] gold matches “fools gold” or “fool’s gold”)
- Escapes special character (e.g. . will treat a . as a literal period instead of parsing it’s special meaning)
- ^
- Matches the starting position within the string
- $
- Matches the ending position of the string
- {number}
- Match number of instances of preceding character
- {number,}
- Match number or more instances of preceding character
- {Number1,Number2}
- Match between Number1 and Number2 instances of preceding characters (inclusive)
rpm Cheat Sheet
Jun 28th
- -i
- Install a package
- -e
- Uninstall a package
- -q
- Query a package
- -U
- Update a package
- -l
- List the files in the package
- rpm -i package name
- Install package name
- rpm -Uvh (--force --nodeps) package name
- Upgrade package name (force installation ignoring dependencies)
- rpm -e package name
- Erase/uninstall package name
- rpm -qvl package name
- Query package name information
sed Cheat Sheet
Jun 28th
- s/regexp/replacement
- If the search is successful, replace regexp with replacement.
- sed ’s/oldword/newword/g’
- Substitute newword for oldword. The g makes the substitution global otherwise only the first occurrence of oldword would be matched.
- sed ’s/word/d’
- Delete the entire line that contains word
- sed ’s/word//’
- Delete just the word word
- sed -n ‘10,20p;20q’
- Print lines 10-20

