nl
stringlengths
13
387
bash
stringlengths
1
532
Write every two lines in "infile" on a single line separated by a comma
cat infile | paste -sd ',\n'
Write every two lines in "infile" on a single line separated by a space
cat infile | paste -sd ' \n'
Write the lines appended to "xxxx" as it appears to the console and append to "yyyy" in the background
tail -F xxxx | tee -a yyyy &
Write out the entire directory hierarchy from the current directory
find .
Write out the entire directory hierarchy from the current directory
find . -print
Write output and error of "bash myscript.sh" to standard output and to "output.log"
bash myscript.sh 2>&1 | tee output.log
Write output of "ls -a" to standard output and to "output.file"
ls -a | tee output.file
Write output of "ls -hal /root/" to standard output and to "/root/test.out"
ls -hal /root/ | sudo tee /root/test.out
Write output of "ls -lR /" to standard output and append to "output.file"
ls -lR / | tee -a output.file
Write output of "ls -lR /" to standard output and to "output.file"
ls -lR / | tee output.file
Write standard input to standard output and file "/tmp/arjhaiX4"
tee /tmp/arjhaiX4
Write standard input to standard output and to "foobar.txt"
tee foobar.txt
Change directory to the parent of the real path of the current script
cd $(dirname $(readlink -f $0))
change the extension of all the ".abc" files in the folder "/the/path" to ".edefg" and do not change in the sub directories. execdir ensures that the command after it is executed only in the folder where the file is found
find /the/path -type f -name '*.abc' -execdir rename 's/\.\/(.+)\.abc$/version1_$1.abc/' {} \;
Change the group of "myfile" to "friends"
chown :friends myfile
change owner and group of the current directory and all files into it to user and group andrew
chown -R andrewr:andrewr *
change owner and group of the file "file" to user "user" and group "group"
chown user:group file ...
Change the owner of "destination_dir" to "user"
chown user destination_dir
change the permissions of all the regular/normal files to 664 in the current folder
find . -type f -exec chmod 664 {} \;
Change the permission to 0755 for all directories under current directory
find . -type d -exec chmod 0755 {} \;
Change permissions to 644 recursively for PHP files.
find . -type f -name '*.php' -exec chmod 644 {} \;
Clean directories and subdirectories of the temporary files generated during normal use
find . \( -name a.out -o -name '*.o' -o -name 'core' \) -exec rm {} \;
Copies all files under current directory like '*FooBar*' to the '~/foo/bar' directory.
find -name '*FooBar*' -print0 | xargs -0 cp -t ~/foo/bar
copy the file header.shtml to each directory under dir1, dir2, dir3, or dir4
find dir1 dir2 dir3 dir4 -type d -exec cp header.shtml {} \;
Count files accessed more than a month ago
find . -atime +30 -exec ls \; | wc -l
Create a compressed archive of "/home" and split the contents into files with at most 4000 MiB each and use prefix "/media/DRIVENAME/BACKUPNAME.tgz"
tar --one-file-system -czv /home | split -b 4000m - /media/DRIVENAME/BACKUPNAME.tgz
create a tar ball of all the jpg and png images in the current folder
find . \( -iname "*.png" -o -iname "*.jpg" \) -print -exec tar -rf images.tar {} \;
create directory /etc/cron.15sec
mkdir /etc/cron.15sec
create directory certs
mkdir certs/
create directory dir1
mkdir dir1
create directory tata
mkdir tata
Create intermediate directories as required and directory /my/other/path/here
mkdir -p /my/other/path/here
Delete all .svn directories under current directory
find . -type d -name .svn -print0|xargs -0 rm -rf
Delete all empty directories under current directory
find -type d -empty
Delete all files in directory $DIR that have not been accessed in at least 5 days
find "$DIR" -type f -atime +5 -exec rm {} \;
Delete all files named 'Waldo' under ~/Books directory tree where '~' expands to user's home directory
find ~/Books -type f -name Waldo -exec rm {} \;
delete all files that have the extension "bam" in current directory
find . -name "*.bam" | xargs rm
Display the 5 smallest files in the current directory and its sub-directories.
find . -type f -exec ls -s {} \; | sort -n | head -5
display all files in current folder
find .
display all files in the current folder
find .
display all files in the current folder
find . -print
display all the files in current folder
find .
display all the files in the current folder
find .
display all the files in the current folder
find . -print
display all the files in the current folder
find ./
display all the files in the current folder.
find .
displays all the files in the current folder
find .
display all files in the current folder which do not match the regular expression
find . -not -regex ".*test.*"
display all the files in the file system which belong to the user "wnj" or which are modified after the file "ttt"
find / \( -newer ttt -or -user wnj \) -print
display all the regular/normal files in the folder "/home/user/demo" which have the permission 777.
find /home/user/demo -type f -perm 777 -print
display all the regular/normal files in the home folder that have been modified in the last 1 day (from the start of day ie, from 00:00 )
find ~/ -daystart -type f -mtime 1
display all the symbolic links in the current folder
find . -type l
display all the symbolic links in the current folder
find ./ -type l
Find a single file called FindCommandExamples.txt under current directory and remove it
find . -type f -name "FindCommandExamples.txt" -exec rm -f {} \;
Find all *.csv files under /foo/bar and move them to some_dir
find /foot/bar/ -name '*.csv' -print0 | xargs -0 mv -t some_dir
Find all *.java files under current directory and archive them to myfile.tar
find . -type f -name "*.java" | xargs tar rvf myfile.tar
Find all *.ogg files under the home directory ignoring the case
find $HOME -iname '*.ogg'
Find all *.ogg (case insensitive) files under your home directory that are less than 100MB in size
find $HOME -iname '*.ogg' -type f -size -100M
Find all *bar files/directories under current directory
find -name *bar
Find all the .c files in the current directory tree that contain the string ‘stdlib.h’
find . -name '*.c' | xargs grep 'stdlib.h'
Find all .java files starting from the current folder
find . -name "*.java"
Find all 0644 permission files/directories under current directory tree and show only the first 10 of them
find . -perm 0644 | head
Find all 777 permission directories and use chmod command to set permissions to 755
find . -type d -perm 777 -print -exec chmod 755 {} \;
Find all Subscription.java files/directories under current directory and enter into the parent directory of the first one found
cd $(find . -name Subscription.java | xargs dirname)
Find all Subscription.java files/directories under current directory and enter into the parent directory of the first one found
cd `find . -name Subscription.java | xargs dirname`
find all the config(.conf files) files in the folder /home/pat
find /home/pat -iname "*.conf"
find all directories in the current folder and do not search in sub directories
find . -type d -maxdepth 1
find all directory list which have empty list in /tmp directory
find /tmp -type d -empty
find all directory list which have empty list in /tmp directory .
find /tmp -type d -empty
Find all directories under current directory and set read & execute permission for group and other for these files
find . -type d -print0 | xargs -0 chmod go+rx
Find all directories under current directory and set read-write-execute permission for owner, read-execute permission for group and no permission for other for those directories
find . -type d -exec chmod u=rwx,g=rx,o= '{}' \;
Find all directories under minimum 1 level down the current directory and set their permission to 755
find . -type d -mindepth 1 -print -exec chmod 755 {}/* \;
find all the directories with the name "some-dir" in the current folder and move them to another folder and do not search in subfolders
find ./ -maxdepth 1 -name "some-dir" -type d -print0 | xargs -0r mv -t x/
Find all files/directories in entire file system that are owned by "shadow" group
find / -group shadow
Find all files/directories in entire file system with 644 permission
find / -perm 644
Find all the files/directories in the entire filesystem that do not belong to user 'wnj' and are not newer than the file/directory 'ttt' by modification time
find / \! \( -newer ttt -user wnj \) -print
Find all files/directories named '.todo' under $STORAGEFOLDER directory tree and print the parent directory names
find "$STORAGEFOLDER" -name .todo -printf '%h\n'
Find all files/directories named file1 under current directory
find -name file1
Find all files/directories that were modified after February 1st under '/usr' directory tree
find /usr -newermt "Feb 1"
Find all files/directories under current directory following symlinks if needed
find -L
Find all files/directories under current directory tree that are owned by 'root'
find . -uid 0 -print
Find all files/directories under current directory tree that have modified in the last 2 days and contain 'blah' (case insensitive) in their names
find . -iname '*blah*' \( -type d -o -type f \) -mtime -2
Find all files/directories with space in their names under current directory
find . -name '* *'
find all the files ending with .ini in the current directory.
find . -name *.ini
find all files in the current directory and sub-directories that were modified after the /etc/passwd file was modified
find -newer /etc/passwd
find all files in the current directory do not display the files which are not readable
find . ! -readable -prune
Find all files in the current directory tree which do not belong to any user
find . -nouser
Find all files in the current directory tree whose size is greater than 1MB
find . -size +1M
find all files in the current folder that have a single letter in their name and have not been modified today
find . -name \? -mtime +0
find all files in current folder using name patterns
find . -iregex ".*packet.*"
find all the files in the current folder which belong to the user root.
find . -user root -perm -4000 -print
find all files in the current folder with the permission 777 and modify the permissions as 755.
find . -type f -perm 777 -exec chmod 755 {} \;
Find all files in the directory $directory or below with the permissions specificed by $permissions.
find "$directory" -perm "$permissions"
Find all the files in entire file system which are modified 50 days back.
find / -mtime 50
find all the files in the entire file system which have been modified in the last 120 hours
find / -mtime -5 -print
Find all the files in file system which are changed in last 1 hour
find / -cmin -60
find all the files in the folder /usr/bin which have been modified in the last 10 days
find /usr/bin -type f -mtime -10
find all the files in the home folder which are empty (Size 0 bytes)
find ~ -empty
Find all files named "file.ext" under the current working directory tree and print its filename
find `pwd` -name "file.ext" -printf "%f\n"
Find all file paths under current directory, sort them numerically and show last 10 lines of output with only their paths
find . -type f -printf '%T@ %p\n' | sort -n | tail -10 | cut -f2- -d" "