andrei bio photo

andrei

Linux engineer, devops enthusiast

Email Github

Some Bash

</tr> </tr> </tr> </tr> </tr> </table>
CommandDescription
netstat -ntlpShows opened ports
nc <ip> <port> -vTest connectivity on specified <ip>:<port>
telnet <ip> <port>Test connectivity on specified <ip>:<port>
nc -l <port> < file.txtOpens up a port and sends the content of the file to whoever connects to that port
rpm -ql <pack.rpm>Shows all files contained by specified RPM file
rpm -qf <file>Search what RPM contains the selected file
rpm -qVVerify if a RPM was altered after installation
typeset|grep TTYShows the name of the terminal you are logged in
env|grep TTYShows the name of the terminal you are logged in
type <binary>Shows the location of a executable file
tcpdump -n -i eth0 tcp port <port>Listen all tcp packets coming on a specified port
lastList of everyone who logged in
wWho is currently logged in
rpmbuild –rebuild package.src.rpmRebuild rpm from sources
rpm -Uvh –nomd5 <link>.src.rpmInstall a src.rpm package
rpmbuild -ba /usr/src/redhat/SPECS/<pachet>.specCompile a spec file
find /location -name “*.txt” -exec grep -l <text> {} \;Searches all files containing <text>
ldd <binary>Shows all libraries used by a file
lsof <binary>Shows all opened files in use by a binary
kill -9 $$Kills current shell session without saving in history
strace -o /locatie/fisier.out <comanda>Logs strace output
sestatusSows selinux staus
setenforce 0Disable selinux
ls | wc -lNumber of files in a folder
command &> file.txt Redirect standard output and standard error to file.txt
command 2>fileStandard error to file
find /tmp -perm -o=wFinds all files that can be written by others
chattr +i <file>set Immutable ON. file cannot be edited until removing flag
ssh -R <port_home>:localhost:22 <user>@<ip_home>Reverse tunnel from remote location to location <home>
ssh -p <port_home> localhostConnect from location <home> to remote location using reverse tunnel
ssh -D 5555 <proxy_host>Connect to a host in order to use the connection as a proxy(in browser) Using port 5555
lynx –mime_header http://site.comReturns headers
python -m SimpleHTTPServerStart a http server in the current location
scp /location/file <user>@<server>:/location/fileCopy file from one server to another
fuser -m /backupSee who uses partition /backup
free -mFree ram space
mount -t nfs <ip>:/location /mount_pointmount nfs partition
dos2unix <file>Prepare a Windows file for Linux
tail -f <file.log>Watch changes on a log file as it gets written
screenStart a screen
Ctrl+A+DDetach screen
screen -lsShow running screens
screen -RReattach screen
screen -xAttach to a not detached screen session
Ctrl+RReverse search
df -hFree space on HDD
du -sh *Show size of all files
dmesg | tailKernel log
grep <word> -riSearch a word in all files in a directory. Reverse+ignore case
tar -p –same-owner -cvf /location/file.tar.gz /location/Archive folder and preserve rights
read -s -p”Password: ” USER_PASSWORD_VARIABLE; echoShell command to read password into variable
ls -lrtList content of folder and sort by date
jobs -lShow running jobs with PID
Ctrl+lClear scree
Ctrl+uClear line
Ctrl+wDelete last word
ps auxList process
test -d <folder> || mkdir <folder>Test if folder exists and create it if it doesn’t
export HISTSIZE=10000Expand history buffer
uname -a |tee out.txtShow output on screen and also write it to file
rpm -q –scripts <RPM>Show pre/post install scripts of an installed RPM
netstat -netShow established connections
mount -o loop imagine.iso /testMount Iso image
iptables -t nat -nLShow redirect rules for iptables
sed s/cookie/brownie/g <cookies.txt >brownie.txtReplace all ”cookie” with “brownie” and write output
tcpdump -i eth0 port <port> and host <host>Listen all TCP on port and from host
sort -t : -k3,2 /etc/passwdSort all lines by the first 2 letters of the 3rd column. Delimiter is “:”
diff -qr /dir1 /dir2Verify if the files from the 2 directories differ
rpm -qlpShow the content of a not installed RPM
rpm2cpio <rpm> | cpio -idmvExtract the content of a RPM
chage -l <user>Expiration date for a user’s password
chage -m 0 -M 99999 -I -1 -E -1 <user>Set a user’s password to never expire
iostatShows read writes to partitions to disk
netstat -pantuShow established connections wih the PID number
stat <file>Show information about a file. Write/read access …
fuser <file>Shows what process is using a file. Useful for unmounting partition troubleshooting
iftrafTool for traffic monitoring
lsof|grep deleteShows deleted files that are still in use. still filling up space
partprobeUpdate kernel info after partition modifications
vmstat 2 3Shows info about ram/swap/io/cpu every 2 seconds 3 times
ps -p $$Show running shell
source .bashrcRerun bashrc
!?Exit status of the last command
!$Parameters of the last command
!!Run last command
$#Number of parameters for a shell script
$11st parameter of a script
tput setaf 1Change font color
sh -x file.shRun in debug mode. Show all steps
arp -naShow arp table
ping <ip>;arpShows the mac address of the pinged ip
arping -I <interfata> <ip>Shows the mac of the ip
ll |awk ‘{print $4}’Print the 4th column
zless <archive>Shows compressed text files
bzless <archive>Shows compressed text files
showmount -e <nfs server>Shows info o a NFS Server
sed ‘s/passwd=[a-f0-9]*/REPLACED PASSWORD/g’ in > outTrim out password from a file
ln -s /usr/share/zoneinfo/UTC /etc/localtimeSet localtime to UTC
cat /etc/servicesShow standard ports
host -t ns domain.comShows NS of a domain
nohup <command/script/..>Runs a script detached from he current shell session
alien file.rpmTransform a rpm to a deb file
dpkg -i file.debInstall a deb file
strace -p <PID> -e trace=network -F -s 5000Network activity of a process
vi /etc/security/access.confDeny users to run cronjobs
chage -d 0 <user>Force a user to change pass at first login
lspciList pci devices
lsusbList usb devices
getfacl /folderGets ACL of a folder
setfacl -m u:test:rw /folderAllow user test rw on the /folder. Partition needs to be mounted with acl option on
grep -v ^# fisier|grep -v -e “^$”Removes comments and white lines and shows the content of a file
:%s/old/new/gFind and replace in VI
kill -USR1 <pid>Shows the progress of a dd command
vi /etc/nologinDeny access to non super user. Show message in file
utmpdump /var/log/wtmpRead login log file
cat /proc/cmdlineShow parameters that kernel loaded at boot
ctrl+x eOpen VI for a long,complicated command
<space> commandDo not save in history
alt .Paste on cli the argument of the last command
dig +short txt keyword.wp.dg.cxSearch Wikipedia for word “keyword” over DNS
sshfs <user>@<host>:/path /local_pathMount folder through ssh. fusermount -u /local_path for umount
vim -x fileAdd password to a file
grep -B 3 <text> <location>Shows the occurrence of <test> plus the 3 rows before. -A after, -C center
pgrep apacheShows all pids of an apache progress
Ctrl+<left>Moves the cursor a word at a time. works in vi and on the command line.works with right arrow also
Ctrl+kDeletes from the end of a line to the cursor.opposite Ctrl+W
rdate -sp <server>Sync clock with ntp.
ntpstatChecks is the time is synchronized with ntp
hdparm -tT /dev/sda1Check disk speed
sshuttle –dns -vvr user@bash.proxy.com 0/0Poor man VPN. easy way to secure ALL trafic through ssh
ab -n 100 -c 10 www.website.comapache benchmark. sends 100 requests, 10 at a time to stress a server
ipcalc -c <ip>/<netmask>Ip calculator
dig @ns0.website <zone> axfrReturns all records from a zone
cat ip12 | grep -E -o ‘(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)’Returns all ips from a file
:(){ :|: & };:Fork bomb
figlet “test”Ascii text
ps aux|awk ‘{print $1 $2}’Print 1st and 2nd column
sed -i “s/foo/bar/g” file Edit the file, replace all occurances of foo with bar
kill -USR1 <pid> Shows the progress of a in progress “dd” command. You can find the pid with ps
find ./ -inum number -exec rm -i {} ;Deletes a file by its inode
ip addr add 192.168.0.1 dev eth0Assign ip address
ip route add 192.168.0.0/23 dev eth0Assign route
route add default gw 10.150.84.1Add default gateway
yum --showduplicates list </td>Shows all rpm versions in repo
mail -s "subject" -r "sender@mail.com" receiver@mail.com <<< "text"Send mail with return address set
ps -o etime </td>How long ago a process was started
cat << 'EOF'|tee input.sh|bash Run commands on separate lines and also add them to script
pkill [part_of_process_name]Kills the processes named part_of_process_name even if its not the full name
shopt -s cdspellYou can change directory even if you misspell the name
cat << EOF >> file.txtStart writing a file line by line until you enter EOF
curl wttr.in/londonWheather in terminal
path=${1?Error argument..}Path receives first argument passed to the script, or Error of no argument
ls *.{sh,py}List all shell and python scripts
tr -dc A-Za-z0-9_ < /dev/urandom |head -c12|xargsGenerate random password
bash | lolcat -a -s 250Make your terminal interactive and fun
cat < index.html</td>Write to file directly from bash
hping3 -c 1 -s 123 -p 80 -S </td>Send one TCP SYN to :80 from source port 123</td></tr>
ping 0|while read a; do echo `date +%T` $a; doneAdd date in front of a ping
crtl+a Go to begining of the line
crtl+e Go to end of the line
lsof -i -Pn Listening and established connections
ps -eLfList running threads
top + 'H'List running threads
lscpuProcessor details. threads/core
yum list installedShows installed packages. Like rpm -qa. Also shows repository that was used
dig NS www.domain.comFind nameservers for a certain domain
dig -x </td>Reverse DNS search for an ip
tcpdump -nn port 53 -c 100Exit exit after first 100 captures disable name and port resolution
dig @[nameserver] [domain] +norecurseGet a non cached response from an authoritive DNS Server
dig +trace</td>Traceroute for DNS queries