Skip to content

Instantly share code, notes, and snippets.

@percyvega
Last active February 3, 2023 22:11
Show Gist options
  • Save percyvega/1289d22abdaf7c1825d89835be9ed64b to your computer and use it in GitHub Desktop.
Save percyvega/1289d22abdaf7c1825d89835be9ed64b to your computer and use it in GitHub Desktop.

List

List current directory's directories
	ls -ld *
List current directory's directories and their files:
	ls -l *
List current directory's contents recursively:
	ls -lR
List specified directory's contents:
	ls dir123 -ltr
List java7 and java8's contents (if they exist):
	ls java[78] -ltr
List matching directory's contents:
	ls *dir?* -ltr

Copy

Copy any output to clipboard
	ls -l > pbcopy
	cat my_file.txt > pbcopy
	pbcopy < myfile.txt
Copy directory and file:
	cp -R dir1 file1 target_dir

Search files for pattern:

grep word_to_find file_name
grep -li H453345 *
grep 9542493967 *2012-12*.logs | egrep "Received MO|Sending to"
grep "Sending to:" smpp_debug_*.log smpp_debug_*.2012-12-12-* | awk ' { print $12 } ' | sort -u

Dispay

Display 3rd column and sort it:
	cut -f 3 movies_info_file.txt | sort
Display 4th column of rows with 2015:
	grep 2015 movies_info_file.txt | cut -f 4

Count number of lines:

cat openSource.txt | wc -l

Find

find ./ -type f -name '*.log' -exec grep '7865165623<' {} /dev/null \;
find . -type d -name .git -depth 2 -execdir sh -c "pwd && git pull" \;
find . -type d -name .git -depth 2 -path "./core-function*" -execdir sh -c "pwd && 	git pull" \;
find . -type d -name .git -depth 2 -not -path "./core-common/*" -execdir sh -c "pwd &	& git pull" \;
find . -type f -name pom.xml -depth 2 -execdir sh -c "pwd && head pom.xml" \;

find ./ -name NAME1
find . -name "api*"
find ./smpp*/ -exec grep "stringToFind" {} /dev/null \;
find . -type d

Archive

tar -cvf compressed.tar myFolder/
tar -xvf compressed.tar

jar -tvf TWAP.war | grep log
jar -xvf db2jcc4.jar

Zip

gzip myTextFile.txt
gzip -dc jre-7u71-solaris-sparc.gz | tar xf -
gunzip compressedFile.tar.gz
unzip wls1213_dev.zip

Various

Remove directory:
	rm -R target_dir

uuencode $FILE_NAME $ATTACHMENT_NAME | mailx -s "my subject" main@tracfone.com
mailx -s "server file contents" pevega@tracfone.com < log14.txt

scp weblogic@dpmaxdev:/tmp/myFile.txt /tmp
scp myFile.txt weblogic@dp-max1:/tmp
scp -r folderWithFiles weblogic@dp-soaprd1:/home/weblogic/.

df -h

du -k | sort -n
du -k .|sort -rn|more
du sort -rn | head -5
du /usr/share | sort -rn | head -5


tail -1000 nohup.out > nohup.out.last1000.txt

head -50 file.txt | tail -10

chmod ugo+-rwx, ugo+-rwx file1
chmod -R 777 myFolder/

cksum test.txt
cksum file1.txt file2.txt

nslookup redhat.com

curl http://dp-str8talk$i:7031/static/build.jsp
curl --head http://dp-csrcbo1:8003/AdfCrmConsole/
curl -v http://dp-str8talk1:7031/static/build.jsp

ssh dp-str8talk1 "ps -ef | grep FAST"

uname -a
cat /etc/issue

nohup node server.js > /dev/null 2>&1 &

nohup means: Do not terminate this process even when the stty is cut off.
> /dev/null means: stdout goes to /dev/null (which is a dummy device that does not record any output).
2>&1 means: stderr also goes to the stdout (which is already redirected to /dev/null).
& at the end means: run this command as a background task.

Replace rta with rtf in all files found:

find . -type f -name 'rta*' | while read FILE ; do
    newfile="$(echo ${FILE} |sed -e 's/rta/rtr/')" ;
    mv "${FILE}" "${newfile}" ;
done

Install packages:

sudo dpkg -i filename.deb
sudo rpm -i filename.rpm

Navigation:

Ctrl-a: home
Ctrl-e: end
Ctrl-f (or arrow right): right
Ctrl-b (or arrow left): left
Alt-f (or Ctrl-right): right a word
Alt-b (or Ctrl-left): left a word
Ctrl-d: delete to the right
Ctrl-h: delete to the left
Alt-d: delete word to the right
Ctrl-w: delete word to the left
Ctrl-k: delete everything to the right
Ctrl-u: delete everything to the left
Ctrl-r (repeat for next): looks for command with specified characters

History

$ history 				// to see the last 10 commands
$ !5 					// executes the history command 5
$ !ls 					// runs last command starting with ls
$ !?etc					// runs last command containing etc
$ echo !$ 				// prints out last parameter
Ctrl+r 					// start typing and will show last match
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment