find . -regextype posix-egrep -regex ".*(rb|js)$"
Find all files ending in .rb or .js.
find . -name "*js" -o -name "*rb"
Same as above, not using regular expressions.
find . -regextype posix-ergep -regex ".*(rb|js)$" -exec grep -l matchNameHere {} \;
Find all files ending in .rb or .js, then search those files for 'matchNameHere'. The -l option prints the line number of the occurance. (http://www.devdaily.com/unix/edu/examples/find.shtml)
find ~/some/directory -name "*rb" -exec basename {} \;
Find all files ending in .rb, then print a list of filenames (no paths). Note that the ';' is mandatory, it tells find where to stop the command execution
find . -type f -newermt "Aug 10" ! -newermt "Aug 17" -exec rm {} \;
Find all files newer than August 10th, not newer than August 17th and remove them
ls *.rb | awk '{print("mv "$1" "$1)}' | sed 's/\.rb/_service\.rb/2' | /bin/sh
Batch rename all files matching a pattern, insert the _service
before the file suffix
find . -name "*erb" | awk '{print($1" "$1)}' | sed 's/\.erb/\.haml/2' | xargs -L 1 -t html2haml $1
Find all files ending in erb
, replace the extension with haml
and then execute the conversion via html2haml
with xargs
-L 1
tells xargs to listen to one line at a time-t
tells xargs to echo the command that it is executing
Fart
find /some/path -name "*rb" -o -name "*yml" | xargs grep -sl "some_phrase" | xargs sed -i -e 's/some_phrase/replacement_phrase'
Find all files ending in *rb or *yml, then grep those files for some_phrase, then replace those instances using sed
cat /some/file.txt | awk '{print "mkdir /path/to/"$0""}' | /bin/sh
Read input from file, pipe to awk to generate a system command, then execute it.
<filename.json python -mjson.tool
Pretty format a JSON file
useradd {username}
Create a new user
chage -d 1 {username}
Force username
to change their password upon the next login
usermod -a -G {groupname} {username}
Adds the user {username} to group {groupname}
$ cat foo.txt
$ ^foo^bar^
=> cat bar.txt
$ aws s3api copy foo.txt --remote foo.txt
$ !!:gs/foo/bar
=> aws s3api copy bar.txt --remote bar.txt
Using the caret ^
operator performs a substitution on the last command that was run. This is useful if you misspell something or need to iterate over some redundant scripts. In the command above, foo.txt
is replaced using the caret with bar.txt
Using the !!:gs
substitution will replace all instances of the line.
Repeat the last run command by using two exclamation points
$ cat foo.txt
$ !!
=> cat foo.txt
Useful for when you need to execute sudo commands
$ cat foo.txt
Permission denied
$ sudo !!
$?
outputs the exit status of the last command$_
run the last command
Return a UNIX timestamp for a custom date on OS X:
date -j -f "%Y-%m-%d %T %z" "2014-06-13 14:35:10 +0700" "+%s"
Reveal certain lines in a file:
sed -n '100,200p' filename.txt
Show biggest files in a directory
du -k | sort -nr | head -n 10
"Signing" a document uses the private key to encrypt it. Anyone with the public key can thus decrypt it. GPG works in reverse by default - uses the public key to encrypt and private key to decrypt. Default usage requires that parties exchange public keys.
To sign a document
gpg --sign file.txt
To decrypt the document
gpg --import public.key
gpg --output file.txt --decrypt file.txt.gpg
See this for more info:
gpg --export -a "User Name" > public.key
export a public key into file public.key. This will create a file called public.key with the ascii representation of the public key for User Name.
gpg --export -a "User Name"
Prints out the public key for User Name to the command line, which is only semi-useful
gpg --export-secret-key -a "User Name" > private.key
Export a private key. This will create a file called private.key with the ascii representation of the private key for User Name.
gpg --import public.key
Import a public key. This adds the public key in the file "public.key" to your public key ring.
gpg --allow-secret-key-import --import private.key
Import a private key. This adds the private key in the file "private.key" to your private key ring. There's a note (*) at the bottom explaining why you may want to do this.
rpm -qli <package-name>
Show installation path for a package
Set the system date
sudo date MMDDHHmmYYYY
sudo date 103109092014