Software Development

A journal for sharing all things software development related


Common Commands

Wed, 12 Jun 2019 11:19 UTC by garethbrown

A collection of common commands on Linux / Bash systems

Toggle Function Key

https://askubuntu.com/questions/23643/how-do-i-disable-the-fn-keys-on-a-laptop

Press Fn+Esc will toggle between enabling/disabling Fn-key functions.

You can also press Ctrl+Shift+T.

Bash

Network

General

	ifconfig

Find gateway

	ip route | grep default

Execute script

Use chmod 700 scriptname first.

./scriptname

Check permissions on files in current directory

ls -lh

Go to last directory

$ cd -

Get disk usage (space)

https://askubuntu.com/questions/400807/is-there-an-easy-command-line-command-to-check-disk-space

$ df -h

Reboot machine

$ sudo reboot

Change owner of file

$ chown

Change file permissions

chmod

Copy to clip board

C-S-c

Paste

C-S-v

Copy contents of one directory to another

$ cp -R app-software-apps-temp/. app-software-apps

https://stackoverflow.com/questions/3643848/copy-files-from-one-directory-into-an-existing-directory

Navigating directories faster

https://mhoffman.github.io/2015/05/21/how-to-navigate-directories-with-the-shell.html

New tab (keyboard shortcut)

C-S-t

Search through history

C-r / C-s

http://www.gnu.org/software/bash/manual/html_node/Searching.html

** Remove Directories **

Force removal recusively

$ sudo rm -rf somefolder

SCP - transfer file to remove server

Copy automation file using scp:

https://unix.stackexchange.com/questions/232946/how-to-copy-all-files-from-a-directory-to-a-remote-directory-using-scp
https://stackoverflow.com/questions/11388014/using-scp-to-copy-a-file-to-amazon-ec2-instance

$ scp -i "~/.ssh/app-software-application-server-key-pair.pem" -r ~/src/app-software-automation ubuntu@ec2-3-8-74-189.eu-west-2.compute.amazonaws.com:~/.

** Print time / date info **

$ timedatectl

Get man (manual) pages

$ man <command>

Concatenate files and print on the standard output

$ cat file1, file2 

Find in file names

(Searching for files starting with BIOS)

find -name "BIOS*"

Find directory

https://www.cyberciti.biz/faq/how-to-find-a-folder-in-linux-using-the-command-line/

find / -type d -iname "actions-runner" 2>/dev/null

find 	     command
/            from root
-type d      directories only
-iname ..    string to search for
2>/dev/null  Prevents error messages for file permission denine

Grep find with file name and line numbers

(Searching for word BIOS in text files)

$ grep -H -n --with-filename "BIOS" *.txt

Exit SSH / docker exec etc.

$ exit

Vi

Move to "command mode" - I have no idea if that's what it's called. Where can call :wq etc

Esc

Insert

Insert

Replace

Insert

Write and quit:

:wq

To open a file:

vi \<file match text \>

Cygwin

Accessing files on Windows C:/

$cd /cygdrive/c

Get path to Cygwin folder on Windows

$cygpath -w ~

https://stackoverflow.com/questions/18909767/cygwin-cant-find-my-files

List running daemons

https://unix.stackexchange.com/questions/175380/how-to-list-all-running-daemons

Various ways of doing this

Cheat sheet:

2lyhw9h3gs331.jpg

Source: https://www.reddit.com/r/linuxmasterrace/comments/bzhtw2/basic_linux_commands/


The information on this site is provided “AS IS” and without warranties of any kind either
express or implied. To the fullest extent permissible pursuant to applicable laws, the author disclaims all warranties, express or implied, including, but not limited to, implied warranties of merchantability, non-infringement and suitability for a particular purpose.

UI block loader
One moment please ...