Posts

Showing posts with the label unix

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 ful...

Creating PostgreSQL table from command line

Using the psql command, we can populate a table that has already been created in the database: $ psql -h <server-hostname>  -d <database> -U <user> -c "COPY <table-name>(col1,  col2,  col3,  col4) FROM STDIN with delimiter as ','" < csvfile.csv For example: $ psql -h mypersonalserver.csdfklecf.us-east-1.rds.amazonaws.com  -d blogdb -U readonly -c "COPY posts(nid,  title,  created,  username,  author,  path,  series) FROM STDIN with delimiter as ','" < historical_posts.csv I've found that I have used this many time to get a quick look at some data. It is one way to populate a table in seconds with one command!