Linux Commands

Last Updated on June 2, 2022

  • soft or sym links: logs -> app/logdata/logs/myapp
    ————————————
    cd – alone goes to home
    cd .. – one up
    cd- – go to prev dir
    ls -d */ – show only directories
  • ————————————
  • uname -a – Check Linux version
  • ————————————
    COPY:
    cp filename.txt /path/to/copy/to
    cp multiple.txt another.txt /path/to/copy/to
    cp multiple.txt another.txt /path/to/copy/to
    cp -p (preserve timestamps)
    cp -nv filename{,.bak} (no overwrite, verbose, add .bak)
  • More on copy command:
    https://www.ionos.com/digitalguide/server/configuration/linux-cp-command
  • ————————————
    Permission Changes: chmod 777 filename
    r (read) – 4
    w (write) – 2
    x (execute) – 1
  • ————————————
    mv filename directory/path
    mkdir – makes folder
    rm -rf – remove -r = recursively and -f = forcefully
    touch file_name another_file – create file or directory
  • View file contents:
    cat – vi – vim
  • ———————————
    find /app -name “log4j” 2>&1 | grep -v “Permission denied” find /app -name “log4j.jar” 2>/dev/null (hides permission denied output)
  • ———————————
    A note about 2>&1
    File descriptor 1 is the standard output (stdout).
  • File descriptor 2 is the standard error (stderr).
    — 2>1 may look like a good way to redirect stderr to stdout. However, it will actually be interpreted as “redirect stderr to a file named 1”. 
    — & indicates that what follows and precedes is a file descriptor and not a filename. So the construct becomes: 2>&1.
  • ———————————
    Create Password Protected ZIP:
    zip -er archivename.zip directory_name
  • ———————————
  • View more locate, find, grep (and other) descriptions here.
    Using locate (searches local file name database)
    (i flag character case non-sensitive)
    locate -i filename.txt
    ———————————
    Using find (searches all files normally)
    find /dir.name/ -name filename.txt
    find . -name filename.txt
    ———————————
    Using grep (finds text within a file)
    grep -r ‘string’ directory-path/
    grep searchTerm filename.txt
    grep -w “abc” file.txt
    ———————————
    DISPLAY CONTENTS:
    head -5 filename.txt (show first 5 lines of file)
    tail -5 filename.txt (show last 5 lines of file)
    diff firstfile.txt secondfile.txt

    history (shows previous used commands)
    man commandName (displays how to use commands)
    netstat

PROCESSES:
df (displays disk space available on file system containing each file name argument)
top (shows processes and details)
ps -ef (process status: all processes and related files)
pstree, uptime, dmesg

Linux Command Flags List:
http://www.catb.org/~esr/writings/taoup/html/ch10s05.html