Useful Unix Commands
May 25, 2010
I can clearly remember the first time I really got excited about computers. It would have been in the late ’80s … I was probably 9-10 yrs old… and I had just finished writing my first batch script in MS-DOS. The machine was a Compaq Portable and it was set up in the corner of my parent’s basement. My dad bought the computer to run Paradox, a relational database management system he used for his research. My sister and I would spend hours squinting at that tiny CRT screen while tapping out essays in WordPerfect or playing text based role playing games like Castle of the Winds.
If I listen carefully I can still hear the whine of our dot matrix printer forcing out a steady stream of perforated listing paper that proceeded to fold slowly on the floor below. When the time came to tear off the sprocket margins and separate each page along it’s perforations I remember feeling positively giddy.
Nothing compared to writing those DOS batch scripts though. It was almost like magic to me. I was in awe of the uncluttered simplicity of logic and loops. Sure, programs like Paradox would perform complex calculations and churned through mountains of data that were exponentially more powerful than anything I was doing, but it performed those routines in a black box. Playing around with batch scripts allowed me to get my hands dirty and observe the nuances of each line of code and command switch
To this day I insist on using the command prompt for a variety of tasks. Here is a list of UNIX commands and scripts that I use frequently:
- Renaming a bunch of files in a directory:
-
for i in *OLDPATTERN*; do; mv $i *NEWPATTERN*; done
- Compressing a folder:
-
tar -zcvf tar-archive-name.tar.gz folder_name
- Extracting a folder:
-
tar -zxvf tar-archive-name.tar.gz
- Dumping a MySQL database to a file:
-
mysqldump -h mysql.hostname.com -u username -p name_of_db > dumpfile.sql
- Restoring a MySQL dump to a database:
-
mysql -h mysql.hostname.com -u username -p name_of_db < dumpfile.sql
- Find and remove files and dirs matching a pattern (ie: *.bak):
-
find . -name "*.bak" -exec rm -rf {} \; - Find and remove files matching a pattern (ie: *.bak):
-
find . -type f -name "*.bak" -exec rm -rf {} \;
Comment
By submitting a comment here you grant ORGANISM a perpetual license to reproduce your words and name/web site in attribution. Inappropriate or irrelevant comments will be removed at an admin's discretion.
1 Comment to Useful Unix Commands
by peter
On July 5, 2010 at 5:36 pm
IBM’s developerWorks has a wealth of resources on UNIX command line best practices. I’ve added two good references to the related links section at the top of the page.