Skip to content

Latest commit

 

History

History
534 lines (314 loc) · 17.3 KB

File metadata and controls

534 lines (314 loc) · 17.3 KB

Terminal

Avevo deciso di imparare qualche comando per il terminale, data la frustrazione continua di dover fare click infiniti per eseguire azioni basilari, come creare un file .txt tramite la GUI.

Per la base ho scelto di utilizzare una delle tante cheat sheet disponibili sul web, ma l'ho modificata un po' per soddisfare le mie esigenze.

Indice


Shortcuts

(indice)

Go to the beginning of the line you are currently typing on.  

This also works for most text input fields system wide.  Netbeans being one exception

+ A

Go to the end of the line you are currently typing on.

This also works for most text input fields system wide.  Netbeans being one exception

+ E

Clears the Screen

+ L

Clears the Screen

+ K

Cut everything backwards to beginning of line

+ U

Cut everything forward to end of line

+ K

Cut one word backwards using white space as delimiter

+ W

Paste whatever was cut by the last cut command

+ Y

Same as backspace

+ H

Kill whatever you are running.  Also clears everything on current line

+ C

Exit the current shell when no process is running, or send EOF to a the running process

+ D

Puts whatever you are running into a suspended background process. fg restores it

+ Z

Undo the last command.

(Underscore.  So it's actually Ctrl + Shift + minus)

+ _

Swap the last two characters before the cursor

+ T

Move cursor one character forward

+ F

Move cursor one character backward

+ B

Move cursor one word forward

+

Move cursor one word backward

+

Swap the last two words before the cursor

+ T

Cut one word backwards using none alphabetic characters as delimiters

+

Auto-complete files and folder names


Core commands

(indice)

Change directory e.g. cd Documents

cd [folder]change directory

Home directory

cdchange directory

Home directory

cd ~change directory

Root of drive

cd /change directory

Previous directory

cd -change directory

Short listing

lslist
[Plumkewe-MacBook:desktop Plumkewe$ ls
GitHub				Scripts
Other
School
Screenshots

Long listing

ls -llistlist
[Plumkewe-MacBook:desktop Plumkewe$ ls -l
total 0
drwxr-xr-x@  33 Plumkewe  staff  1056 Aug 22 01:59 GitHub
drwxr-xr-x  199 Plumkewe  staff  6368 Aug 22 00:23 Other
drwxr-xr-x   10 Plumkewe  staff   320 Jul 30 00:12 School
drwxr-xr-x@  86 Plumkewe  staff  2752 Aug 19 13:37 Screenshots
drwxr-xr-x    8 Plumkewe  staff   256 Aug 22 02:40 Scripts

Listing incl. hidden files

ls -alistlistlist
[Plumkewe-MacBook:desktop Plumkewe$ ls -a
.		.DS_Store	.localized	Other		Screenshots
..		.idea		GitHub		School		Scripts

Long listing with Human readable file sizes

ls -lhlist
[Plumkewe-MacBook:desktop Plumkewe$ ls -lh
total 0
drwxr-xr-x@  33 Plumkewe  staff   1.0K Aug 22 01:59 GitHub
drwxr-xr-x  199 Plumkewe  staff   6.2K Aug 22 00:23 Other
drwxr-xr-x   10 Plumkewe  staff   320B Jul 30 00:12 School
drwxr-xr-x@  86 Plumkewe  staff   2.7K Aug 19 13:37 Screenshots
drwxr-xr-x    8 Plumkewe  staff   256B Aug 22 02:40 Scripts

Entire content of folder recursively

ls -Rlist
[Plumkewe-MacBook:desktop Plumkewe$ ls -R
GitHub		Other		School		Screenshots	    Scripts

./GitHub: Kitsune-Translations ...

./GitHub/Kitsune-Translations: Localizations README.md ...

Run command with the security privileges of the superuser (Super User DO)

sudo [command]super user do

Opens a file ( as if you double clicked it )

open [file]open

Displays active processes. Press q to quit

toptable of processes
Processes: 384 total, 2 running, 382 sleeping, 1423 threads            02:52:38
Load Avg: 1.79, 1.65, 1.69  CPU usage: 0.94% user, 1.53% sys, 97.51% idle
SharedLibs: 224M resident, 45M data, 60M linkedit.
MemRegions: 126075 total, 2045M resident, 76M private, 741M shared.
PhysMem: 8162M used (2925M wired), 28M unused.
VM: 6183G vsize, 2317M framework vsize, 53980655(0) swapins, 56295739(0) swapout
Networks: packets: 12928380/15G in, 13852515/6460M out.
Disks: 16802996/431G read, 35391275/428G written.

PID COMMAND %CPU TIME #TH #WQ #PORT MEM PURG CMPRS PGRP 64950 top 1.9 00:01.42 1/1 0 26 4504K 0B 0B 64950

Opens the file using the nano editor

nano [file]Nano's ANOther editor

Opens the file using the vim editor

vim [file]Vi IMproved

Clears the screen

clearclear

Resets the terminal display

resetreset

Chaining commands

(indice)

Run command A and then B, regardless of success of A

[command-a]; [command-b]

Run command B if A succeeded

[command-a] && [command-b]

\ | [command-b] | Run command B if A failed

[command-a] || [command-b]

Run command A in background

[command-a] &

Piping commands

(indice)

[command-b] | Run command A and then pass the result to command B e.g ps auxwww \ | grep google

[command-a] | [command-b]

Command history

(indice)

Shows the stuff typed – add a number to limit the last n items

history n
[Plumkewe-MacBook:desktop Plumkewe$ history 4
519  ls -R
520  top
521  nano readme.md
522  history 4

Interactively search through previously typed commands

+ r

Execute the last command typed that starts with ‘value’

![value]
[Plumkewe-MacBook:desktop Plumkewe$ !to
touch readme.md

Print to the console the last command typed that starts with ‘value’

![value]:p
[Plumkewe-MacBook:desktop Plumkewe$ !t:p
touch readme.md	

Execute the last command typed

!!
[Plumkewe-MacBook:desktop Plumkewe$ !!
touch readme.md	

Print to the console the last command typed

!!:p
[Plumkewe-MacBook:desktop Plumkewe$ !!
touch readme.md	

File management

(indice)

Create a new file

touch [file]

Full path to working directory

pwdprint working directory
[Plumkewe-MacBook:desktop Plumkewe$ pwd
/Users/Plumkewe/desktop

Current folder, e.g. ls .

.
[Plumkewe-MacBook:desktop Plumkewe$ ls .
GitHub		School		Scripts
Other		Screenshots	readme.md

Parent/enclosing directory, e.g. ls ..

..

Long listing of parent directory

ls -l ..list
[Plumkewe-MacBook:desktop Plumkewe$ ls ..
Applications					Public
Bootstrap Studio Backups		README.md
CLionProjects					WebstormProjects

Move 2 levels up

cd ../../change directory

Concatenate to screen

catconcatenate

Remove a file, e.g. rm data.tmp

rm [file]remove

Remove with confirmation

rm -i [file]remove
[Plumkewe-MacBook:desktop Plumkewe$ rm -i readme.md
remove readme.md? n/y

Remove a directory and contents

rm -r [dir]remove

Force removal without confirmation

rm -f [file]remove

Copy file to file

cp [file] [newfile]copy

Copy file to directory

cp [file] [dir]copy

Move/Rename, e.g. mv file1.ad /tmp

mv [file] [new filename]move
[Plumkewe-MacBook:desktop Plumkewe$ mv CIA.txt novabb.txt

Copies file contents to clipboard

pbcopy < [file]pasteboard copy

Paste clipboard contents

pbpastepasteboard paste

Paste clipboard contents into file, pbpaste > paste-test.txt

pbpaste > [file]pasteboard paste

Directory management

(indice)

Create new directory

mkdir [dir]make directory

Create nested directories

mkdir -p [dir]/[dir]make directory

Remove directory ( only operates on empty directories )

rmdir [dir]remove directory

Remove directory and contents

rm -R [dir]remove

Output file content delivered in screensize chunks

less [file]

Push output to file, keep in mind it will get overwritten

[command] > [file]

Append output to existing file

[command] >> [file]

Tell command to read content from a file

[command] < [file]

Search

(indice)

Search for files, e.g. find /Users -name "file.txt"

find [dir] -name [search_pattern]find

Search for all lines that contain the pattern, e.g. grep "Tom" file.txt

grep [search_pattern] [file]globally search a regular expression and print

Recursively search in all files in specified directory for all lines that contain the pattern

grep -r [search_pattern] [dir]globally search a regular expression and print

Search for all lines that do NOT contain the pattern

grep -v [search_pattern] [file]globally search a regular expression and print

Search for all lines that contain the case-insensitive pattern

grep -i [search_pattern] [file]globally search a regular expression and print

Spotlight search for files (names, content, other metadata), e.g. mdfind skateboard

mdfind [search_pattern]metadata find

Spotlight search for files named like pattern in the given directory

mdfind -onlyin [dir] -name [pattern]metadata find

Help

(indice)

Offers help

[command] -hhelp
[Plumkewe-MacBook:desktop Plumkewe$ cd --help
-bash: cd: --: invalid option
cd: usage: cd [-L|-P] [dir]

Offers help

[command] --helphelp
[Plumkewe-MacBook:desktop Plumkewe$ cd --help
-bash: cd: --: invalid option
cd: usage: cd [-L|-P] [dir]

Offers help

info [command]information

Show the help manual for [command]

man [command]manual

Gives a one-line description of [command]

whatis [command]what is
[Plumkewe-MacBook:desktop Plumkewe$ whatis grep
grep(1), egrep(1), fgrep(1), zgrep(1), zegrep(1), zfgrep(1) - file pattern searcher
grep(1), egrep(1), fgrep(1), rgrep(1), bzgrep(1), bzegrep(1), bzfgrep(1), zgrep(1), zegrep(1), zfgrep(1) - file pattern searcher
git-grep(1)              - Print lines matching a pattern

Searches for command with keywords in description

apropos [search-pattern]
[Plumkewe-MacBook:desktop Plumkewe$ apropos write
BIO_get_buffer_num_lines(3ssl), BIO_set_read_buffer_size(3ssl), BIO_set_write_buffer_size(3ssl), BIO_set_buffer_size(3ssl), ...