Skip to content

Instantly share code, notes, and snippets.

@joepol
Last active November 27, 2022 11:35
Show Gist options
  • Save joepol/0be2177f433bc57f0ed64ad9b4792e90 to your computer and use it in GitHub Desktop.
Save joepol/0be2177f433bc57f0ed64ad9b4792e90 to your computer and use it in GitHub Desktop.
useful Linux (Ubuntu) shell commands

Redirection of both out and err channels to a file ,

(redirects stdout to a file and redirects stderr to "where" stdout is redirected)

./SCRIPT_NAME > out.txt 2>&1 

Get live update of a file (in terminal)

tail -f your.log

Get full process path

1. sudo ls -l /proc/PID/exe
2. ps -auxwe | grep PID

Prints all environment variables to a file

SET > env_vars.txt

Kill a process (by name)

pkill PROCESS_NAME 
e.g
pkill java

Show all files/directories in current directory as a list and with permissions

(if followed by a file name - will show the symlink of the file if such exists)

ls -la
ll

When typing a command and forgetting to type sudo.. you can type this command

and it will run The last command with sudo (called : sudo bang bang)

sudo !!

Copy files using ssh

scp FILES_TO_COPY MACHINE_USERNAME@IP:/MACHINE_DIRECTORY_TO_COPY_TO

Add current directory to lib (where dynamic .so files should found)

export LD_LIBRARY_PATH=.

Open file browser with access to sudo, (nautilus - or any other file browser)

sudo nautilus

Unzip and unarchive | compress and archive

tar xzf FILE_NAME.tar.gz   | tar -czvf ARCHIVE_NAME.tar.gz PATH_TO_FILE_OR_DIRECTORY

Create an empty file

touch FILE_NAME

Empty trash

rm -rf ~/.local/share/Trash/*

Get all installed compliers (can be used for different packages as well...)

dpkg --list | grep compiler

Listen to UDP packets using Netcat

nc -l -u PORT_NUMBER

Send a UDP packet

echo "This is a UDP message" > /dev/udp/127.0.0.1/3000

Change users password

sudo passwd USERNAME

Change file ownership

sudo chown USERNAME FILE_NAME

Important paths

Repositories of apt (Advanced Package Tool)

/etc/apt/sources.list

Network configurations

/etc/network/interfaces

Show groups and binded users

cat /etc/group

Users list

cat /etc/passwd

Startup commands

cat /etc/rc.local

Check for 3d acclearaion when ubuntu runs on VirtualBox

/usr/lib/nux/unity_support_test -p

Mount network directory

sudo mkdir /mnt/LOCAL_SHARED_NAME
sudo mount -t cifs //IP_TO_SHARE/PATH /mnt/LOCAL_SHARED_NAME -o username=USERNAME,password="PASSWORD"

Dump communication from all network interfaces of some IP to screen , with ASCII

tcpdump --list-interfaces
tcpdump -i any host <IP_ADDR> -A

System information

Get system details

uname -a 
cat /proc/cpuinfo

Verbose hardware details

sudo lshw 

Show ubuntu version

lsb_release -a

Search

Search files (starting from root directory)

find / -name "*SOME_NAME*"

Find file path, can use regex too

locate FILE_NAME 

Find directory of an app

which APP_NAME

Find a pattern in files in directory (whole word)

grep -rnw '/path/to/somewhere/' -e 'pattern'
grep -Ril "text-to-find-here" /   

Comilation

objdump -d YOURFILE > YOURFILE.asm

see / increase stack size

ulimit -a
ulimit -S -s 16384 //16MB

Memory usage of a process

pmap

/************* Keyboard shortcuts *************
//copy/paste ctrl+shift+c or ctrl+shift+v

Lock screen

Ctrl + Alt + L

Open terminal

Ctrl + Alt + T

right click

Shift + F10

add later

top -H -p (pidof <PROCESS_NAME>)
chrt -m 
gdb <PATH_TO_ELF/SO> <PATH_TO_CORE_FILE>
lsof -anP -i tcp  -SHOWS CONNECTIONS SOURCE AND DEST
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment