nl_command
stringlengths
14
387
bash_code
stringlengths
0
532
Remove sequence like '\xEF\xBB\xBF' from first string of every '*.js' file in a current folder and subfolders, creating backup file with .bak extension for every changed file, and removing backup on success.
find . -iname *.js -type f -exec sed 's/^\xEF\xBB\xBF//' -i.bak {} \; -exec rm {}.bak \;
prints top 10 commands used
history | awk '{print $2}' | awk 'BEGIN {FS="|"}{print $1}' | sort | uniq -c | sort -nr | head
Copy the standard output of a "bash" session to "/var/log/bash.out.log"
bash | tee /var/log/bash.out.log
List all files with their paths that have identical content.
find * -type f | xargs md5sum | sort | uniq -Dw32
Get the total sizes of all files under current directory
find . -type f -printf '%p %s\n' | awk '{sum+=$NF}END{print sum}'
Write every two lines in "infile" on a single line separated by a comma
cat infile | paste -sd ',\n'
Compresses all files in the directory 'PATH_TO_FOLDER' without recursion and keeps uncompressed files from deletion.
find PATH_TO_FOLDER -maxdepth 1 -type f -exec bzip2 -zk {} \;
Unzip "file.gz", list the unique lines matching regex pattern '"searchstring":"[^"]*"' prefixed by the number of occurrences, sort from least frequent to most frequent
zcat file.gz | grep -o '"searchstring":"[^"]*"'| sort | uniq -c | sort -n
find directories under the $LOGDIR directory where there have been no modifications for 5 days and deletes them.
find $LOGDIR -type d -mtime +5 -exec rm -f {} \;
show all the ".acc" files in the folder /home
find /home -type f -name '*.aac'
Search all .java files residing in the current directory tree and modified at least 7 days ago for string "swt"
find . -name '*.java' -mtime +7 -print0 | xargs -0 grep 'swt'
Prints line count of each file within current directory.
find . -type f -print | xargs -L1 wc -l
get all files in a current directory modified in the last day
find . -mtime -1 | xargs tar --no-recursion -czf myfile.tgz
delete all the mp3 files in the home folder
find /home/ -exec grep -l “mp3” {} \; | xargs rm
beginning at the end of the file, prints lines matching /2012/ and exits after first non-matching line
tac error.log | awk '{if(/2012/)print;else exit}'
Find all foo.mp4 files in the current directory tree and print the pathnames of their parent directories
find ./ -name "foo.mp4" -printf "%h\n"
Write the shell's input to standard error as it is read
set -v
List unique MD5 digests of all files in the current directory ending in .txt
md5sum *.txt | cut -d ' ' -f 1 | sort -u
search for the word "mysql" in all the files in the current containing the word "notes" in their name
find . -iname "*notes*" | xargs grep -i mysql
Find all .c and .C files in the current directory tree that contain "main(" and copy them to directory test1/
find -iname “*.c” -exec grep -l ‘main(‘ {} \; -a -exec cp {} test1/ \;
Set variable "filename" to only the name of document specified by URL, in this case "pic.jpg"
filename="`basename "http://pics.sitename.com/images/191211/pic.jpg"`"
Search the current directory recursively for files last modified within the past 24 hours
find . -mtime 0
display all the regular/normal files in the current folder which have been modified in the last 24 hours
find . -mtime 0 -type f
display all hidden files in the current folder
find . -type f -name ".*"
Print the input "hello world" to the console followed by a swap of the first two awk fields
echo hello world | tee /dev/tty | awk '{print $2, $1}'
Find all php files under current directory
find . -type f -name "*.php"
Find all files/directories under current directory tree that contain 'pattern' in their names
find -name "*pattern*"
List all *.txt files/directories under current directory
find . -name "*.txt" -exec $SHELL -c 'echo "$0"' {} \;
Search regular files from the /path/to/dir directory tree for lines that contain "_START" and are enclosed in lines "@GROUP" and "@END_GROUP"
find /path/to/dir -type f -exec sed '/@GROUP/,/@END_GROUP/!d' {} \; | grep '_START'
Find all files that contain the case insensitive regex 'stringtofind' in maximum 1 level down the / directory without descending into other partitions
find / -maxdepth 1 -xdev -type f -exec grep -li stringtofind '{}' \;
display all the regular/normal files in the /root folder which are bigger than 500MB
find /root -type f -size +500M -printf "The %p file is greater than 500MB\n"
display all the files in the file system which are smaller than 20 bytes
find / -size 20
Show who is logged on
who
listing of the files starting from home dir, that have size 50k or less and have extention html."
find . \ -name '*.html' \ -exec ls -l {} \; 2> /dev/null
Print the last white space separated field of every line in "file.txt" as a ", " separated list
awk '{print $NF}' file.txt | paste -sd, | sed 's/,/, /g'
Find *.html files in the current directory tree that were last modified more than 7 days ago
find . -mtime +7 -name "*.html" -print
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`
Archive "/var/www/test/" to "/var/www/test" on host "231.210.24.48" as user "ubuntu" via ssh using identity file "/home/test/pkey_new.pem"
rsync -rave "ssh -i /home/test/pkey_new.pem" /var/www/test/ [email protected]:/var/www/test
Delete files under $LOCATION that match $REQUIRED_FILES in their names and were modified more than 360 minutes ago
find $LOCATION -name $REQUIRED_FILES -type f -mmin +360 -delete
display all directories in the entire file system
find / -type d -print
Print the names of all files in /some/directory and its subdirectories recursively whose MIME type is video
find /some/directory -type f -exec file -N -i -- {} + | sed -n 's!: video/[^:]*$!!p'
Find all *.txt files/directories under current directory
find . -name "*.txt"
get the root access
sudo su -
display all files in current folder which are bigger than 100KB but are less than 500KB
find . -size +100k -a -size -500k
Push the directory containing the first existing command found in all arguments to the directory stack.
pushd $(dirname `which $@`)
Find all .zip files in the current directory tree
find . -depth -name *.zip
find all files and directories under the current directory and display the filesize followed by the filename, using the stat command on FreeBSD/OSX
find . -type f -exec stat -f "%z %N" {} \;
Find files smaller than 40 blocks skipping directories on other file systems
find . -size -40 -xdev -print
Make 3 directories named "~/Labs/lab4a/folder" followed by the number 1, 2, or 3
mkdir ~/Labs/lab4a/folder{1..3}
Create a tar archive with all *.java files under the current directory
find . -type f -name "*.java" | xargs tar cvf myfile.tar
find all the directories in the current folder which have been modified in 24 hours and move them to the folder /path/to/target-dir
find . -depth -type d -mtime 0 -exec mv -t /path/to/target-dir {} +
display all the files in the current folder which have been modified after the files "/bin/sh"
find . -newer /bin/sh
Unzip "myDB.sql.gz" to standard output as input to "pg_restore ..."
gzip -cd myDB.sql.gz | pg_restore ...
change cgi files to mode 755
find htdocs cgi-bin -name "*.cgi" -type f -exec chmod 755 {} \;
find all normal/regular files in current folder and display them in sorted order
find . -type f -ls | awk '{print $, $, $, $NF}'
Find file1 in the level 1 directories and above
find -maxdepth 2 -name file1
Split "$ORIGINAL_FILE" into files of at most "$MAX_LINES_PER_CHUNK" lines each with a prefix "$CHUNK_FILE_PREFIX"
split -l $MAX_LINES_PER_CHUNK $ORIGINAL_FILE $CHUNK_FILE_PREFIX
Send e-mail to "[email protected]" with subject "any subject" containing process statistics output by the GNU version of 'top'.
top -b -n 1 | mail -s "any subject" [email protected]
long list all the files in the curent folder starting with "Tes"
find . -type f -name "Tes*" -exec ls -l {} \;
Find all *~ files/directories under dir and print an rm command for each of them for deletion
find dir -name \*~ | xargs echo rm
Search only for directories
find -type d
Create a symbolic link named "$1/link" to the current working directory
ln -s "`pwd`" $1/link
Delete all files under and below the current directory
find -mindepth 1 -delete
Find all directories under $FOLDER, take the first fields (dot (.) as the delimiter) from their timestamps and reverse sort them numerically
find "$FOLDER" -type d -printf "%T@\n" | cut -f 1 -d . | sort -nr
recursively delete, without prompting, directories under /data/bin/test, that are older than 10 days and where the name starts with a number
find /data/bin/test -type d -mtime +10 -name '[0-9]*' -print | xargs rm -rf ;
display all files in the boot directory prepending each filename with STDERR, STDOUT accordingly
3>&1 1>&2 2>&3 | sed 's/^/STDERR:/'
Read a line from standard input and save each word in the bash array variable "arr"
read -a arr
Variable PID contains a process ID, check if this process exists - resulting exit status from this command will be zero if it does and current user has permission to send it signals.
kill -0 $PID
Installs 'php-mbstring' package, enabling 'remi' repository.
yum --enablerepo=remi install php-mbstring
Print summary of new/missing files, and which files differ between /path/to/folder1 and /path/to/folder2, sorted alphabetically.
diff -rq /path/to/folder1 /path/to/folder2
List all files under and below the directory given as variable $FULFILLMENT
find $FULFILLMENT -ls
Make directory "~/public_html"
mkdir ~/public_html
Print file type of the command "c++"
file `which c++`
Copies all files like "*FooBar*" under the current directory to the '~/foo/bar' directory.
find . -name '*FoooBar*' | sed 's/.*/"&"/' | xargs cp ~/foo/bar
Find files with size more than 200557600B and which are more than 2 days old under ${userdir}/${i}/incoming directory and remove them
find ${userdir}/${i}/incoming -mtime +2 -type f -size +200557600c -exec rm {} \;
Perform a white space safe search for all files/directories under current directory
find . -print0 | xargs -0
Go to /tmp directory.
cd /tmp
Count the number of lines in "/etc/fstab"
cat /etc/fstab | wc -l
Delete all files/directories older than 48 hours in /path/to/files* paths
find /path/to/files* -mtime +2 -delete
Find all files/directories under current directory with the null character as the delimiter
find -print0
Mount partition with label "WHITE" on "/mnt/WHITE" with read and write permission
mount -L WHITE /mnt/WHITE -o rw
Find all files/directories with '.js' extension under current directory tree without descending into './directory'
find . -path ./directory -prune -o -name '*.js' -print
Search for aaa in all files under current directory and count the number of matches
find . -type f -exec grep -o aaa {} \; | wc -l
display all the files in the entire file system
find / -type f -exec echo {} \;
find all files that names are game
find / -name game
Print numbers from 1 to 30 with a leading 0
seq -w 30
Unset all environment variables.
unset `env | awk -F= '/^\w/ {print $1}' | xargs`
Bind mount "/original/path" on "/new/path"
mount --bind /original/path /new/path
Print the empty directories and files under current directory
find -empty
Perform a dry run to recursively copy "test/a" to "test/dest" excluding "test/a/b/c/d"
rsync -nvraL test/a test/dest --exclude=a/b/c/d
Search for "ifconfig" in the output of "history" and print 5 lines that precede and follow
history | grep -C 5 ifconfig
Print all non-hidden files in the current directory and its subdirectories
find . -not -path '*/\.*'
searches through the /usr directory for the regular file named 'Chapter1*'
find /usr -name "Chapter*" -type f
Prints long recursive listing of all content of a current folder, saving output to 'output.file'.
ls |& tee files.txt
Enables shell option 'compat31'.
shopt -s compat31
Prints only unique lines of './script.sh' output.
./script.sh | sort -u
Finds string with text "string to be searched" in any cased files like "*.cs" recursively in a current folder.
find ./ -type f -iname "*.cs" -print0 | xargs -0 grep "content pattern"
Convert all DOS files under and below the current directory to the Unix format
find . -type f -print0 | xargs -0 -n 1 -P 4 dos2unix
Find all directories in the current directory tree that do not have `execute' permissions for anyone
find . -type d ! -perm -111
delete what was typed in the command line and run "pwd" when button "\e[24~"
bind '"\e[24~":"\C-k \C-upwd\n"'