Useful Linux Commands

# add text to the start of a line
sed -i -e 's_.*_REPLACETHIS&_' <filename>
# Will remove the word Javascript from the file cewlfile
cat cewlfile | tr -d \[:CHAR:Javascript\]

RTFM

Useful tool help remind you of command syntax

git clone https://github.com/leostat/rtfm
cd rtfm
pip3 install terminaltables
./rtfm.py -e hydra #EXAMPLE
# 1. redo last command but as root
sudo !!

# 2. open an editor to run a command
ctrl+x+e

# 3. create a super fast ram disk
mkdir -p /mnt/ram
mount -t tmpfs tmpfs /mnt/ram -o size=8192M

# 4. don't add command to history (note the leading space)
 ls -l

# 5. fix a really long command that you messed up
fc

# 6. tunnel with ssh (local port 3337 -> remote host's 127.0.0.1 on port 6379)
ssh -L 3337:127.0.0.1:6379 [email protected] -N

# 7. quickly create folders
mkdir -p folder/{sub1,sub2}/{sub1,sub2,sub3}

# 8. intercept stdout and log to file
cat file | tee -a log | cat > /dev/null

# bonus: exit terminal but leave all processes running
disown -a && exit

Commands Explained

Kill a process using a port

Append to end of file

sed

Copy output of command to clipboard

Then Ctrl v to paste You may have to install xclip

Crontab

  • Sytanx:

  • 1 * * * * $ cmd runs every minute

Extracting archives

Compressing archives

Copy files remotely

File Permissions

  • t rwx rwx rwx type / owner / group / world

  • Type is directory (d) or file (-).

  • read (r) 4

  • write (w) 2

  • execute (e) 1

  • chmod 755 test.sh Make a file executable

  • find . -name "*.php" -type f -exec chmod 755 {} \;

Finding Files

  • Update the database of file names on the system

  • Reads the database and shows the location of a file

  • Show the path where the app is executed from

  • Show all the files that start with sbd

  • Show all world readable directories

  • Show all world executable directories

Searching within files

  • Search for the pattern xxx in a fil

  • Search recursively for a pattern in a director

  • Search for a pattern in a zip file

Locate, Which, Find

Locate

Which

Searches directories that are defined in $PATH

Find

More aggressive search tool that can recursively search any given path for various files

Others

  • Import CA in java store

curl

display webpage to terminal - text

Whats running on a port

Last updated

Was this helpful?