List
ls
Flags
-l
---> show in long format
-a
---> all directories (including dots)
-h
---> show unit suffixes
-t
---> sort by time modified
-tr
--> reverse time sort order
-S
---> sort by size
-Sr
--> reverse size sort order
-ld
--> list directories as plain files
Example
ls -lat
ls -latr
Good for limiting the scope of a wildcard search to the current directory
ls -lahd *dev*
Tar
Zip and unzip different files and directories as a Text ARchive file using different compression methods.
tar
c
--> create
x
--> extract
v
--> verbosely
f
--> to file
z
--> gzip compress
u
--> update
C
--> to a non-current directory
tar
--> no compression
tar.gz
--> gzip compression
tar.bz2
--> bzip2 compression
Create
Create tarchive from source directory
tar -cvf filename.tar source_directory/
tar -cvfz filename.tar.gz source_directory/
tar -cvfj filename.bz2 source_directory/
Trailing slash on source directory is essential for tarchiving Solr schemas on a Mac
tar -cvfz myhiwayschema.tar.gz myhiwayschema/
List
List all files in tarchive
tar -tvf filename.tar /source_file_directory
Extract
Extract file into current working directory as folder called "filename"
tar -xvf filename.tar
tar -xvfz filename.tar.gz
tar -xvfj filename.bz2
Extract file into some other already created directory
tar -xvf filename.tar -C /other/directory/
Don't overwrite or replace
tar -xvfk filename.tar
Extract specific file(s)
tar -xvf filename.tar filename_1 filename_2
SSH
Secure Shell access to a remote console
ssh username@hostname
ssh username@11.22.33.44
SCP
Securely copy a file from source host to target host.
Copy from local to remote
scp /local/a.png username@remote:/remote/a.png
Copy from remote to local
scp username@remote:/remote/a.png /local/a.png
May be good to spell out the whole local path /Users/username/Desktop/a.png
Copy multiple files to a directory
scp *.png user@remote:/directory/
Copy directory to directory
scp -r localdirectory username@remote:/home/username/
scp -r username@remote:/home/username/ localdirectory
Specify a host port (capital -P)
scp -r -P 44444 /Users/username/Desktop/this.png username@remote.com:/home/user/images/
scp -r -P 44444 username@remote:/home/user/images/this.png /Users/username/Desktop/