Skip to content

Instantly share code, notes, and snippets.

@venkatmarepalli
Last active February 28, 2019 18:41
Show Gist options
  • Select an option

  • Save venkatmarepalli/7789dcdf56294f1d232c79a93ce27048 to your computer and use it in GitHub Desktop.

Select an option

Save venkatmarepalli/7789dcdf56294f1d232c79a93ce27048 to your computer and use it in GitHub Desktop.
Handy Shell Commands
#How to determine the current shell I'm working on?
#Ref: https://stackoverflow.com/questions/3327013/how-to-determine-the-current-shell-im-working-on
echo $SHELL
echo $0
ps -ef | grep $$ | grep -v grep
#Find Linux Kernel version
uname -a
#Find Linux Version info
cat /proc/version
#Distribution version
cat /etc/*release
#Command to display chmod permissions of a file
stat -c '%a %n' *
stat -c '%a %n' filename
#Disk usage
du -xk | sort -n | tail -25
#Summarize and display current directory disk usage in human readable format ex: 10K, 11M etc
du -sh
#Copying files from local to ssh
scp filenameFromCurrDir username@machinename:/home/user/folder
#Getting files from remote machine to current machine. Executing scp in reverse way
scp username@remoteMachineName:/file/to/send /where/to/put
# Copying files from EC2 instance into the current directory (.)
scp -i ~/.ssh/pemfile ec2-user@ip-address:/path/of/the/file/to/copy .
#Taring
tar -cvf myfile_20030617.tar folderinCurrentDir/*
#UnTaring
tar -xf abc.tar
#list of ports running
netstat -lntu
#list of ports running with service name
netstat -tlnp
#Translate Domain name into IP Address
host www.google.com
nslookup www.google.com
#List all packages installed on the system, This is ony for Ubuntu or any Debian-based systems
#Src: https://help.ubuntu.com/lts/serverguide/dpkg.html
dpkg -l
dpkg -l | grep apache2
#List the files installed by package
dpkg -L package_name
#Checking size of the file or directory
# Ref: https://stackoverflow.com/questions/11720079/how-can-i-see-the-size-of-files-and-directories-in-linux
ls -l filename # Size of the file
ls -l * # Size of All the files in the current directory */
ls -al * # Size of All the files including hidden files in the current directory */
ls -al dir/ # Size of All the files including hidden files in the 'dir' directory */
#Gives you the summarized(-s) size of the directory in human readable(-h) format*/
du -sh directory_name
#Gives you the apparent(-b) summarized(-s) size of all the files and directories in the current directory in human readable(-h) format*/
du -bsh *
#Test if scripts in cron.hourly or cron.monthly are working or not
#If by running this command it shows your file it means it worked. Otherwise, if doesn't show anything your file name is not valid.
#The files in cron.hourly or cron.monthly should not have any extension ex: Rename script.sh to script by removing the extension
run-parts --test /etc/cron.hourly
#While running previously executed commands one can use !52 to execute 52nd command
#To see the full previous command type first few characters and press Esc+P
#To see a part phrase ex: cp a/b/c/ d/e/f when you type a/b and Esc+/ you will see /a/b/c/
#How to Check if Your Linux System Is 32-bit or 64-bit
lscpu
#If cpu op-modes displays both 32 bit and 64 bit then it is 64 bit os running on the machine
#Ref:https://www.howtogeek.com/198615/how-to-check-if-your-linux-system-is-32-bit-or-64-bit/
#To create a 30GB random “dockerfile”, do this:
dd if=/dev/urandom of=dockerfile bs=30GB count=1
#To allow any display to be displayed on your machine when connecting using ssh and setting DISPLAY variable this setting helps. (One doesnt have to ssh with X option)
xhost +
#https://stackoverflow.com/questions/6377009/adding-public-key-to-ssh-authorized-keys-does-not-log-me-in-automatically
#You need to verify the permissions of the authorized_keys file and the folder / parent folders in which it is located.
#just generate a ssh key like:
ssh-keygen -t rsa -C "your_email@youremail.com"
#copy the content of ~/.ssh/id_rsa.pub and lastly add it to the remote machines ~/.ssh/authorized_keys
scp -r ~/.ssh user@remotemachine:./
cp ~/.ssh/id_rsa.pub ~/.ssh/authorized_keys
chmod 700 ~/.ssh
chmod 600 ~/.ssh/authorized_keys
#You may also need to change/verify the permissions of your home directory to remove write access for the group and others.
chmod go-w ~
#Split file into multiple parts -d for numeric
split -d -b 18350k nginx_error_psgi.log nginx_error_
#Concatenate primary and intermediate certs for installing it on nginx server
cat your_domain_name.crt intermediate.crt >> bundle.crt
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment