nl
string
bash
string
Count all the mp3 files in the music user's home and subdirs.
find ~music -type f -iname *.mp3 | wc -l
count all the regular files that are present in a directory
find . -type f | wc -l
Counts all top-level files in a current folder.
ls -1 | wc -l
count amount of jobs running
jobs | wc -l
Count and show the number of lines for each PHP files in the current directory tree
find . -name '*.php' | xargs wc -l
Count files in $DIR_TO_CLEAN that are older than $DAYS_TO_SAVE days
find "$DIR_TO_CLEAN" -mtime +$DAYS_TO_SAVE | wc -l
Counts lines in each *.cpp, *.c, *.h file.
wc -l `find . -type f \( -name "*.cpp" -o -name "*.c" -o -name "*.h" \) -print`
Counts lines in each *.php file sorted by file path.
find . -name '*.php' -type f | sort | xargs wc -l
Counts lines in each *.php file, sorted by number of lines, descending.
find . -name '*.php' -type f | xargs wc -l | sort -nr
Counts lines in each of *.php files in a current folder and subfolders and prints total count as well.
find . -name "*.php" | xargs wc -l
Counts lines in each of *.php files in a current folder and subfolders and prints total count as well.
wc -l **/*.php
Counts lines in each of *.php files in a current folder and subfolders ignoring 'tests' folder and prints total count as well.
find . -name tests -prune -o -type f -name '*.php' | xargs wc -l
Counts lines in each of *.php files in a current folder and subfolders ignoring 'tests*' folders and prints total count as well.
find . -name "*.php" -not -path "./tests*" | xargs wc -l
Counts lines in each of *.php files in current folder with subfolders and prints total count as well.
find . -name '*.php' | xargs wc -l | sort -r
Counts lines in file 'filename' ignoring empty lines and lines with spaces only.
cat 'filename' | grep '[^ ]' | wc -l
Counts lines of 'file' file.
wc -l file
Counts lines of /dir/file.txt file.
cat /dir/file.txt | wc -l
Counts lines of /dir/file.txt file.
wc -l /dir/file.txt
Counts lines of /etc/fstab file.
cat /etc/fstab | wc -l
Counts lines of all *.txt files in a current folder.
cat *.txt | wc -l
count lines of C or C++ or Obj-C code under the current directory
find . \( -name "*.c" -or -name "*.cpp" -or -name "*.h" -or -name "*.m" \) -print0 | xargs -0 wc
count the lines of java code for all the java files in the current directory
find . -name "*.java" -print0 | xargs -0 wc
Counts lines of myfile.txt file.
cat myfile.txt | wc -l
Counts lines with all-cased word 'null' in file 'myfile.txt'.
grep -n -i null myfile.txt | wc -l
Counts non-empty lines in file fileName.
cat fileName | grep -v ^$ | wc -l
Counts number of *.php files in a current folder and subfolders.
find . -name '*.php' | wc -l
Count the number of .gz files in the current directory tree
find -name "*.gz" | wc -l
Count the number of .gz files in directory tree /home/user1/data1/2012/mainDir
find /home/user1/data1/2012/mainDir -name '*.gz' | wc -l
Count the number of .java files in all folders rooted in the current folder
find . -name "*.java" | wc -l
Count number of A records of domain '$domain' on nameserver '$server' and save value in 'result' variable
result="$(dig +short @"$server" "$domain" | wc -l)"
Count the number of all directories under current directory non-recursively
find . -mindepth 1 -maxdepth 1 -type d | wc -l
Count the number of all directories under directory '/mount/point' non-recursively
find /mount/point -maxdepth 1 -type d | wc -l
Count the number of areas that differ in "file1" and "file2" with 0 lines of unified context
diff -U 0 file1 file2 | grep ^@ | wc -l
Count the number of characters in the list of regular files from the current directory tree
find . -type f | xargs | wc -c
Count the number of differing lines in "file1" and "file2"
diff file1 file2 | grep ^[\>\<] | wc -l
Count the number of directories in the current directory and below
find . -type f -exec basename {} \; | wc -l
Count the number of equal lines in sorted files "ignore.txt" and "input.txt"
comm -12 ignore.txt input.txt | wc -l
Count the number of files/directories named file1 under current directory
find -name file1 | wc -l
Count the number of files/directories with '.php' extension under current directory tree and change the permissions to 755
find . -name "*.php" -exec chmod 755 {} \; -exec /bin/echo {} \; | wc -l
Count the number of files in the /usr/ports directory tree whose names begin with 'pkg-plist' and which contain 'etc/rc.d/'
find /usr/ports/ -name pkg-plist\* -exec grep -l etc/rc.d/ '{}' '+' | wc -l
Count the number of files in the /usr/ports directory tree whose names begin with 'pkg-plist' and which contain 'unexec.rmdir%D'
find /usr/ports/ -name pkg-plist\* -exec grep 'unexec.rmdir %D' '{}' '+' | wc -l
Count the number of files in the current directory and below
find . -type d -exec basename {} \; | wc –l
Count the number of files in the directory trees whose pathnames match pattern '/dev/sd*[a-z]'
find /dev/sd*[a-z] -printf . | wc -c
Count the number of files in the directory trees whose pathnames match pattern '/dev/sd*[a-z]'
find /dev/sd*[a-z] | wc -l
Count the number of files named `file1'
find -name file1 | wc -l
Count the number of lines in "/dir/file.txt"
cat /dir/file.txt | wc -l
Count the number of lines in "/etc/fstab"
cat /etc/fstab | wc -l
Count number of lines in "Sample_51770BL1_R1.fastq.gz"
zcat Sample_51770BL1_R1.fastq.gz | wc -l
Count the number of lines in "myfile.txt"
cat myfile.txt | wc -l
Count the number of lines in "testfile" wrapped to fit in a width of "$COLUMNS" characters
fold -w "$COLUMNS" testfile | wc -l
Counts the number of lines in *.php and *.inc files in a current folder and subfolders.
find . -name '*.php' -o -name '*.inc' | xargs wc -l
Count the number of lines in all ".php" files in the current directory tree
find . -name '*.php' -type f | xargs cat | wc -l
Count the number of lines in all ".php" files in the current directory tree
wc -l `tree -if --noreport | grep -e'\.php$'`
Count the number of lines in all ".txt" files
cat *.txt | wc -l
Count the number of lines in all files in the xargstest/ directory tree that match pattern 'file??'
find xargstest/ -name 'file??' | sort | xargs wc -l
Count number of lines in all files matching "*R1*.fastq.gz"
zcat *R1*.fastq.gz | wc -l
Count the number of lines in each .java file in the current directory tree
find . -name "*.java" -exec wc -l {} \;
Count the number of lines in every regular .rb file in the current directory tree
find . -name "*.rb" -type f -exec wc -l \{\} \;
Count the number of lines in every regular .rb file in the current directory tree
find . -name "*.rb" -type f -print0 | xargs -0 wc -l
Count the number of non localhost users
who | grep -v localhost | wc -l
Count number of occurences of "123" in the string "123 123 123" (ie. 3)
echo "123 123 123" | grep -o 123 | wc -l
Count the number of regular files in the current directory that contain a vowel in their names
find . -maxdepth 1 -type f -iname '*[aeiouy]*' -printf ".\n" | wc -l
Count the number of the regular files residing under and below ./randfiles/
find ./randfiles/ -type f | wc -l
Count the number of regular files with 755 permission under current directory tree
find . -type f -perm 755 | wc -l
Count the number of total files and folders under current directory tree
find . -print0 | tr -cd '\0' | wc -c
Count the number of unique duplicate lines in "file1" and "file2" combined
sort file1 file2 | uniq -d | wc -l
Count the number of unique lines in sorted file "a.txt" compared to sorted file "b.txt"
comm -23 a.txt b.txt | wc -l
Count the number of users logged in
who | wc -l
Count the occurrence of 2 in the string '1 1 2 2 2 5'
echo "1 1 2 2 2 5" | tr ' ' $'\n' | grep -c 2
Counts total lines in all *.php files in the current directory recursively
find . -name '*.php' -type f | xargs cat | wc -l
Count the total number of lines in all "*.gz" files in the current directory tree after decompression
find . -type f -name '*.gz' | xargs zcat | wc -l
Count total number of lines in all *txt files in current directory
wc -l `find . -type f -name '*.txt' `
Count the total number of lines in all HTML files under /usr/src that contain string "foo"
find /usr/src -name "*.html" -execdir /usr/bin/grep -H "foo" {} ';' | wc -l
The cpio command is a copy command designed to copy files into and out of a cpio or tar archive, automatically preserving permissions, times, and ownership of files and subdirectories.
find . | cpio -pdumv /path/to/destination/dirrectory
Create 5 empty .txt files
echo "a.txt b.txt c.txt d.txt z.txt" | xargs touch
Create 6-letter named temporary directory in a folder path that is provided as the first positional parameter, and save the path to it in a variable 'tmp'
tmp=$(mktemp -d $(dirname "$1")/XXXXXX)
Create 6-letter named temporary file in a folder path $file1, and save the path to it in a variable 'tmpfile'
tmpfile=$(mktemp $(dirname "$file1")/XXXXXX)
Create 6-letter named temporary file in a folder path that is provided as the first positional parameter, and save the path to it in a variable 'tmpfile'
tmpfile=$(mktemp $(dirname "$1")/XXXXXX)
Create 998 directories one inside another with sequential names folder1, folder2, ... folder998 and create an additional folder named 'folder9991000' inside the last 'folder998' directory
mkdir -p folder$( seq -s "/folder" 999 )1000
create a backup of all the files in the current folder excluding those that are present in the .snapshot sub directory and excluding the swap files (files ending with ~)
find . -name .snapshot -prune -o \( \! -name *~ -print0 \) | cpio -pmd0 /dest-dir
create a backup of all the files in the current folder to the floppy and save the file list in the file /tmp/BACKUP.LOG
find . -cpio /dev/fd0 -print | tee /tmp/BACKUP.LOG
create a backup of all the files in the home folder on a partition and save the log to a file
find /home -depth -print | cpio -ov -0 /dev/rmt0 | tee -a tape.log
create a backup of all the files which have been modified in the last 48 hours
find source/directory -ctime -2 | cpio -pvdm /my/dest/directory
create a compressed archive "filename.tar.gz" with verbose output
tar -cvzf filename.tar.gz folder
Create a compressed archive from "www" and split the contents into files of at most 1073741824 bytes and use prefix "www-backup.tar."
tar czf - www|split -b 1073741824 - www-backup.tar.
create a compressed archive in my_dir directory matching '.[^.]* ..?*' glob pattern
tar -C my_dir -zcvf my_dir.tar.gz .[^.]* ..?* *
create a compressed archive with files newer than 1st of January 2014, 18:00:00.
tar -N '2014-02-01 18:00:00' -jcvf archive.tar.bz2 files
Create a copy of index.html in all directories in current directory, pausing for confirmation before overwriting any existing files - names may not contain spaces - names may not contain spaces.
find . -mindepth 1 -maxdepth 1 -type d| xargs -n 1 cp -i index.html
Create a copy of index.html in all directories in current directory whose name contains Va, pausing for confirmation before overwriting any existing files - names may not contain spaces.
find . -mindepth 1 -maxdepth 1 -type d| grep \/a |xargs -n 1 cp -i index.html
create a cpio archive of the entire contents the current directory while preserving the permissions, times, and ownership of every file and sub-directory
find . -depth -print | cpio -o -O /target/directory
Create a directory named 'alpha_real' in the current directory
mkdir alpha_real
Create a full path symbolic link "$newlink" from a relative path symbolic link "$origlink"
ln -s $(readlink -f $origlink) $newlink
Create a gzip archive file ($tarFile) of all *.log files under $sourcePath
find $sourcePath -type f -name "*.log" -exec tar -uvf $tarFile {} \;
create a hard link as directory named "new_hard_link" to the directory "existing_dir" as root
sudo ln -d existing_dir new_hard_link
Create a hard link named "my-hard-link" to "myfile.txt"
ln myfile.txt my-hard-link
create a link to all the html or htm files in the current folder which have been changed in the last 30*24 hours
find \( -name "*.htm" -o -name "*.html" \) -a -ctime -30 -exec ln {} /var/www/obsolete \;
create a list of all files in all subdirectories
find . -type f -exec md5 {} \;
Create a local SSH tunnel from "localhost" port 16379 to "localhost" port 6379 using key "keyfile.rsa" and disables the interactive shell
ssh -i keyfile.rsa -T -N -L 16379:localhost:6379 someuser@somehost
Create a new directory "existing-dir/new-dir/" on host "node"
rsync /dev/null node:existing-dir/new-dir/
Create a new RSA key for ssh with no passphrase, store it in ~/.ssh/id_rsa without prompting to overwrite if this file exists, and minimize output from ssh-keygen.
echo -e 'y\n'|ssh-keygen -q -t rsa -N "" -f ~/.ssh/id_rsa