-
-
Save jgeek/28329007702134f7ff72 to your computer and use it in GitHub Desktop.
Linux commands
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Generate ssl key: | |
openssl req -new -newkey rsa:2048 -nodes -keyout server.key -out server.csr | |
find files recursively: | |
find . -name "*.bak" -type f -delete | |
But use it with precaution. Run first: | |
find . -name "*.bak" -type f | |
---------- | |
You can discover process groups using GNU ps as follows: | |
ps x -o "%p %r %y %x %c " | |
kill -9 -processGroupId | |
--------- | |
ssh tunnle: | |
ssh -L localport:server_address:server_port username@server_address -p ssh_port | |
installing chrome: | |
wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb | |
sudo dpkg -i google-chrome-stable_current_amd64.deb | |
--------------- | |
# tar complete tutorial: | |
http://www.tecmint.com/18-tar-command-examples-in-linux/ | |
$ tar -xvzf zookeeper-3.4.5.tar.gz | |
$ zip -r compressed_filename.zip foldername | |
$ unzip filename.zip | |
# creating pasword protected zip file: | |
$ zip -r -P <password> compressed.zip your_folder | |
$ zip -e compressed.zip file.txt | |
------------ | |
sudo chmod +x k290_fnkeyctl | |
sudo ./k290_fnkeyctl | |
----------- | |
hg st |grep -v ? | |
list files which does not have ? | |
----------- | |
export LD_LIBRARY_PATH=/usr/local/lib | |
-------------- | |
protoc filename.protoc --java_out=. | |
compiling the proto file | |
cat `hg root`/.hgignore | |
hg st |grep ? | |
hg st |grep -v ? | |
hg st |grep ?|cut -d' ' -f2 | |
abort: outstanding uncommitted merges | |
hg update --clean -r tip | |
------------- | |
for f in `find . -name "*.java"`;do wc -l $f;done | |
for f in `find . -name "*.java"`;do wc -l $f;done|cut -d' ' -f1|paste -sd+|bc //be is calculator | |
------------- | |
installing maven 3 | |
sudo apt-get install gdebi | |
wget http://ppa.launchpad.net/natecarlson/maven3/ubuntu/pool/main/m/maven3/maven3_3.2.1-0~ppa1_all.deb | |
sudo gdebi maven3_3.2.1-0~ppa1_all.deb | |
sudo ln -s /usr/share/maven3/bin/mvn /usr/bin/maven | |
*if you prefer to have the binary called mvn instead of mvn3 you can simply do the following: | |
sudo ln -s /usr/bin/mvn3 /usr/bin/mvn | |
--------------------- | |
search in file contents: | |
grep slf4j . -r -a 1 (-a 1 : print one line after found word) | |
---------------- | |
export JAVA_HOME=/usr/local/java/jdk1.6.0 | |
export PATH=$JAVA_HOME/bin:$PATH | |
---------------- | |
ssh-keygen | |
ssh-copy-id user@<ipaddress> | |
ssh-add | |
SH_AUTH_SOCK=0 ssh -vvv user@host | |
Setting SSH_AUTH_SOCK=0 bypasses the ssh-agent, and adding a key enables the ssh-agent to answer in the correct way | |
----------- | |
ssh-keygen -t rsa -b 2048 | |
----------- | |
unzip myFile.war -d /home/app/ | |
------------------ | |
$ touch tgs.txt | |
$ touch -c a.txt //do not create new file if does not exist | |
$ touch a b c d | |
$ stat tgs.txt | |
$ touch -a tgs.txt //changing access time | |
$ touch -m *.o //changing modification time | |
NOTE: It is not possible to change the ctime using touch command | |
$ touch -t [[CC]YY]MMDDhhmm[.SS] | |
CC – Specifies the first two digits of the year | |
YY – Specifies the last two digits of the year. If the value of the YY is between 70 and 99, the value of the CC digits is assumed to be 19. If the value of the YY is between 00 and 37, the value of the CC digits is assumed to be 20. It is not possible to set the date beyond January 18, 2038. | |
$ touch -a -m -t 203801181205.09 tgs.txt | |
$ touch -d "2012-10-19 12:12:12.000000000 +0530" tgs.txt | |
touch a.txt -r tgs.txt // will update the time-stamp of file a.txt with the time-stamp of tgs.txt file | |
--------------------- | |
$ vim etc/rc.local | |
/home/elite/utility/k290_fnkeyctl | |
exit 0 | |
-------------------- | |
# search in repo cache for package_name | |
$ apt-cache search package_name | |
# to support exfat file system | |
$ sudo apt-get install exfat-fuse exfat-fuse | |
# disk usage | |
$ du -hs (human readable, summerized) | |
or | |
$ sudo apt-get install ncdu | |
$ ncdu | |
# CPU average load | |
$ cat proc/loadavg == $ uptime | |
# cowsay: print all cows! | |
$ for f in /usr/share/cowsay/cows/*; do cowsay -f "${f:23:-4}" "${f:23:-4}"; done | |
# in the case of package could not for 'add-apt-repository' first run: | |
$ apt-get install software-properties-common | |
# /etc/sources.list | |
$ sudo add-apt-repository "deb http://us.archive.ubuntu.com/ubuntu/ saucy universe multiverse" | |
# install java | |
$ cp jdk1.8.0_40_folder /usr/local/java | |
$ sudo update-alternatives --install "/usr/bin/java" "java" "/usr/local/java/jdk1.8.0_40/jre/bin/java" 1 | |
$ sudo update-alternatives --install "/usr/bin/javac" "javac" "/usr/local/java/jdk1.8.0_40/bin/javac" 1 | |
$ sudo update-alternatives --install "/usr/bin/javaws" "javaws" "/usr/local/java/jdk1.8.0_40/bin/javaws" 1 | |
$ sudo update-alternatives --set java /usr/local/java/jdk1.8.0_40/jre/bin/java | |
$ sudo update-alternatives --set javac /usr/local/java/jdk1.8.0_40/bin/javac | |
$ sudo update-alternatives --set javaws /usr/local/java/jdk1.8.0_40/bin/javaws | |
# list ports | |
$ netstat -nlp|grep 5555 | |
--------------- | |
# setting java home | |
ou can set your JAVA_HOME in /etc/profile as Petronilla Escarabajo suggests. But the preferred location for JAVA_HOME or any system variable is /etc/environment. | |
Open /etc/environment in any text editor like nano or gedit and add the following | |
JAVA_HOME="/usr/lib/jvm/open-jdk" (java path could be different) | |
Use source to load the variables, by running this command: | |
source /etc/environment | |
Then check the variable, by running this command: | |
echo $JAVA_HOME | |
---------------------- | |
# find files and show pass each found file to du -hs | |
$ locate da3c820e56c3| parallel du -hs | |
$ locate da3c820e56c3| xargs -L1 du -hs | |
--------------- | |
# print pc name | |
$ cat /etc/hostname | |
------------ | |
$ rsync -azvh --progress zk [email protected]: | |
--------- | |
# computer name: | |
$ cat /etc/hostname | |
$ cat /etc/hosts | |
--------------- | |
# run java app in background | |
$ nohup java -jar /web/server.jar & | |
--------- | |
# setting java home | |
$ sudo vim /etc/environment | |
JAVA_HOME=/usr/local/java/jdk1.8.0_40 | |
export JAVA_HOME | |
$ . /etc/environment | |
------------ | |
# setting default editor of system to vim | |
$ export EDITOR=vim | |
export permenently: | |
$ vim ~/.bashrc | |
add the the following line at the end: | |
export EDITOR=vim | |
-------------- | |
add a direcotry to path: | |
export PATH=$PATH:my_path | |
--------- | |
# net tools: | |
$ sudo jnettop -i eth0 | |
$ sudo iotop | |
$ sudo nethogs | |
----------- | |
# netcat example: | |
nc localhost 3333 < prod1/access.log | |
nc -l 3333 | |
for (( ; ; )) do nc localhost 3333 < tomcat_logs/localhost_access_log.2015-08-20.txt ; sleep 1;done | |
------------- | |
curl oauth2 commands: | |
curl -u security_service:sianat_secret -X POST http://localhost:8080/oauth/token -H "Accept:application/json" -d "username=ali&password=ali&grant_type=password&scope=read" | |
curl http://localhost:8082/spring-security-oauth-resource/foos/1 -H "Authorization: Bearer d28a6436-769e-44b4-a1f2-f4c9c7c4564a" | |
curl -X POST http://localhost:8081/spring-security-oauth-server/oauth/check_token -d "token=37b4c205-2005-4ee8-9e91-eaab99287e24" | |
------- | |
archiving with 7z: | |
This will create 5MB size files from the ubuntu.iso. | |
The -v5m is the volume size so you can change it to 10, 12, 1, 3 and also the m can be changed to k for kilobytes, etc; | |
the -mx0 switch tells 7-Zip to use no compression, that is, just to split data into parts. | |
# 7z a -v5m -mx0 ubuntu.7z ubuntu.iso | |
To extract just do: | |
# 7z x ubuntu.7z.001 | |
----------- | |
# ubuntu server set root pass: | |
$ sudo -i | |
$ sudo passwd | |
--------------- | |
install clan bomber: | |
http://askubuntu.com/questions/44763/how-do-i-install-the-game-clanbomber | |
------------ | |
# delete recursively all file with .bak suffix | |
find . -name "*.bak" -type f -delete | |
------- | |
http://ubuntuhandbook.org/index.php/2014/10/tor-browser-4-0-released-ubuntu-1404/ | |
------- | |
find files contains a text: | |
grep -rnw '/path/to/somewhere/' -e "pattern" | |
-r or -R is recursive, | |
-n is line number, and | |
-w stands match the whole word. | |
-l (lower-case L) can be added to just give the file name of matching files. | |
Along with these, --exclude or --include parameter could be used for efficient searching. Something like below: | |
grep --include=\*.{c,h} -rnw '/path/to/somewhere/' -e "pattern" | |
This will only search through the files which have .c or .h extensions. Similarly a sample use of --exclude: | |
grep --exclude=*.o -rnw '/path/to/somewhere/' -e "pattern" | |
Above will exclude searching all the files ending with .o extension. Just like exclude file it's possible to exclude/include directories through --exclude-dir and --include-dir parameter; for example, the following shows how to integrate --exclude-dir: | |
grep --exclude-dir={dir1,dir2,*.dst} -rnw '/path/to/somewhere/' -e "pattern" | |
------------ | |
tcp send hex | |
echo -n -e "x01x18x03" | nc 192.168.1.4 80 | |
nc 127.0.0.1 1200 < binary.bin > response.bin | |
echo '0006303030304e43' | xxd -r -p | nc -l localhost 8181 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment