UNIX/Linux

UNIX/Linux

Some of the DLTs (Dirty Little Tricks) for UNIX/Linux.


# Find all the file name with specific pattern and copy to a folder
find data/ -type f -name "S[0-9]*.tsv" | xargs -i cp {} sparccOutput/



# Find any files with particular pattern inside all directories
grep --recursive --ignore-case --files-with-matches "CANCELLED" Root_RST-04-106/


# Count the number of files within a folder.
ls -F |grep -v / | wc -l

#  List just the names of matching files
grep -l 'main' *.c

# Search directories recursively. Search for all the files under the directory  '/home/Rootstocks'
grep -r 'Maxifort' /home/Rootstocks

# Output context around the matching lines. Example- display header and first line of sequence for each header. 
grep -C 2 '^>' *
# AND grep
grep 'apple' /home/test | grep 'ball'

Some example wit Stream editor - sed


# This would output the word "Rootscion" because sed found the string "stock" in the input. 
echo Rootstock | sed 's/stock/scion/'


# Count file with sepecific name within a folder
ls -dq *apple_* | wc -l

# Display folder size
du -sh */


# Find and copy files with matching name/pattern
find ./fungi_sparcc/ -name 'R*.txt' -exec cp -prv '{}' '/home/rp3448/ufrc/analysis/output' ';'


# Take in the file name and create a same diretory and the move the file into the created folder.
#!/bin/bash
for file in *
do 
mkdir -p -- ${file%.*} 
mv -- $file ${file%.*} 
done


Avatar
Ravin Poudel
Computational Biologist (PostDoc)

Related