Useful Unix commands

Useful as reference:

echo $BASH : a path gets displayed ‘/bin/bash’

ls -la /data ( display in the sub directory)

ls -R (shows more details – recursively)

/ used in man search

ctrl p / ctrl n ( command history)

cat <filename>

less <filename>

search with /

reset (if terminal set by any binary files)

file <filename> : will give info about file

open <file>

rm <file>

mv <filename> //rename

mkdir a

mkdir a, b , c, d

touch <filename> //create a new file

open . (opens current dir in finder)
cp file.txt . (copies to current dir)
cp subsir/file.txt demo.txt (copies from subdir and uses the name demo.txt)

cp -R ( copies dir as well…)

mv <file> targetpath

rm <filename>

rmdir <dirname>

Safety switch -i

It will ask before doing dangerous things

cp -Ri

mv -ri

ls a* (All files strating with a)

ls -d (Lists only directories)

? match single char

[abcd] match anything that has a b c or d

[^a-c] not matching a through c

rm file[234] ( will remove file2 through file4)

rm file[^234] ( will remove anything not in 2 3 or 4)

rm file?.doc ( will remove all which has a single character)
touch {a..c}{1..3}.txt (creates 9 files)

ls -lR > listing.txt (output to a file)

ls -lR >> output.txt ( appended to the file)

cat > story.txt ( usefult to create files)

echo >> story.txt ( same like story ..just appends)


ls | lesss ( combine ls and less)

grep text <filename> ( will find text in filename and it’s occurrences)

cut -f 3 oscars.tsv | grep 4 | wc -l ( Piping counting number of movies with 4 oscars)


echo “hello $,(whoami)”


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s