Change User Password (Linux Command)

# sign on to the "root" account
$ su
$ passwd user

When Ubuntu Stop Responding

  • Press <Ctrl> <Alt>
  • Hit <SysRq>, R, E, I, S, U, B

Copy Directory

$ cp -a <dir1> <dir2>

Cut and Paste Directory

$ mv -v <dir1> <dir2>

Run a Shell Script

$ chmod +x /path/to/file
$ ./path/to/file

Count Number of Lines of A File

$ cat <file> | wc -l

Combine Multiple Files to One

$ cat <file1> <file2> ... <filen> > <file>

Generate New File from Few Lines of A Larger File

# line1 to line20
$ sed -n '1,20p;21q' larger_file.txt > newfile.txt

Find Files by Name

# NOTE: `locate` is much younger than `find` and it only has one big advantage over `find` -- speed`
$ locate <file>

Rename All Files in A Directory (with a prefix)

# for FILENAME in *; do mv $FILENAME prefix_$FILENAME; done

Find al files containing specific text on Linux

$ grep -rnw 'path/to/somewhere' -e 'pattern'

# -r or -R is recursive
# -n is line number
# -w match the whole word
# along with --exclude, --include, --exclude-dir flags for efficiency

# This will only search through those files which have .c and .h extensions
$ grep --include=\*.{c,h} -rnw 'path/to/somewhere' -e 'pattern'
$ grep --include=\*.py -rnw 'path/to/somewhere' -e 'pattern'

results matching ""

    No results matching ""