Anna Syme

Click name ↑ to return to homepage


#search for a word in a file
grep "word" file.txt

#search in all the files in a directory
grep -r "word" directory/


#tell me about the join command
man join

#symlink files
ln -s realname.ext fakename.ext

#see history but cut line numbers at start
history | cut -c 8-

#wget files
#get ftp address of file
wget <ftp address>

#format a tabular file in view
less file.txt | column -t 


#sort table (a tsv) by number in col 3
sort -nk 3 file.txt > sorted.txt

#sort a table and keep the header
# extract header
head -1 file.txt > sorted.txt
# extract all but header
# then sort by reverse number in col 2
tail -n+2 file.txt | sort -nrk 2 >> sorted.txt


#glob: a pattern for searching filenames
#NOTE: can be different to regex
#show all files ending in .txt
echo *.txt 

#remove a file with certain chars in the name
#use a backslash to escape the char
# note: not a forward slash. important!
# if filename is (file).txt

rm \(file\).txt