BASH

Reload

  • Run exec bash to start a new bash terminal in place of the current one.

Bookmarking locations

  • I use the method described by Jeroen Janssens in his blog post.
  • I got the jump scripts from here.

Completion

  • You want to enable extra completion to get completion for e.g. Makefile targets
  • The bash-completion plugin provides this and can be installed via your package manager

Sudoers

  • Link showing how to add user to sudoers

Search and Replace Text in a file

  • Use and external program like perl or sed
  • perl -pi -e 's/abc/XYZ/g' /tmp/file.txt
  • sed -i -e 's/abc/XYZ/g' /tmp/file.txt
  • mssql-server package ships with a replace tool
    • replace "abc" "XYZ" -- file1.txt

Extract Files from an RPM

  • rpm2cpio ./packagecloud-test-1.1-1.x86_64.rpm | cpio -idmv

Check the dependencies of a program

  • ldd /usr/bin/ffmpeg

Extract column from data

  • awk '{print $2}' prints the second column of data

Copy list of files to another folder and maintain folder structure

  • <command to generate file list> | cpio --pass-through --verbose --make-directories -u ../tmp/f1/f2/

Find unique entries in a file

  • If sorted then uniq -c
  • If not sorted then either sort | uniq -c or awk '~cnts[$0]++'. The awk version has the advantage of not needing to sort the file first so can operate on larger files. See here

Tree

  • This is a useful command to print the contents of a folder in a tree like manner.

File System maintenance

  • lsblk will list the volumes and where they're mounted in a tree like manner.
  • Extend or reduce LVMs. Shows how to create the physical partitions, extend the logical partitions and resize the file system.

Ncdu

  • This is a terminal based program to show disk usage and which folders are taking up the most space. You can navigate the file system from it and delete files and folders. Install using yum.

Wrapping Command Line tools

  • Can wrap command line tools by creating a function of the same name which performs what every operations you want and then delegates to the built in function. See here

AWK

Replace common prefix of files

  • rename <old_prefix> <new_prefix> <files>

Git

  • Reset local master to be the same as the remote master branch git fetch origin git reset --hard origin/master

results matching ""

    No results matching ""