UNIX Quick Hit
UNIX Quick Hit
I was doing some work on the command line and thought it would be helpful to list out some useful Unix tidbits.
List files in human readable format
$ ls -lhS
-l use a long listing format
-h with -l, print sizes in human readable format (e.g., 1K 234M 2G)
-S sort by file size
You can use man ls to see all possible parameters
FIND
Recursively find all files with extension .pyc
$ find <directory> -type f -name "*.pyc"
For example, if you were looking for all .pyc files in your local directory and all sub directories you would type
$ find . -type f -name "*.pyc"
How to Create an SSH Shortcut
If you find yourself ssh'n to the same host repeatedly, I recommend creating a shortcut for this command in the config file in your .ssh directory.
$ cd ~/.ssh
$ vim config
From here, you can now create shortcuts. You can specify the hostname, username, port, and the private key. For a full list of options, visit the official docs. Here's an example of how to structure the file:
Host example2
HostName example.com
User root
Host example3
HostName 64.233.160.0
User userxyz123
Port 56000
IdentityFile /Users/myuser/Documents/mypem.pem
Now, you can simply SSH into any of these servers with these simple commands:
$ ssh example2
$ ssh example3
SCREENS
An easy way to keep processes running even when you close a window or disconnect from a server. I'm not going to go full on into screens because honestly I don't use them that much. Check here if you are interested
Comments
Post a Comment