Thursday, April 5, 2007

Linux command cheat sheet

Linux Cheat Sheet

Getting Around in the File System
pwd
Path of working directory - tells you what directory you are in

ls
List - Lists the files in the current directory

ls -l

Lists the files and their attributes

cd

change directory - Change to the directory specified

Dealing with Files

cp

copy - Make a copy of a file

cp -R

Make a copy of a directory

mv

move - Move or rename a file

rm

remove - Delete a file

more

Page through a file.

grep

Search a file for a keyword

vi

Edit a file. (See Ruling WebGUI's vi Cheat sheet for details>

chmod

change mode - Change the mode or permissions on a file.
Mode = ogw or owner, group, world permissions. example: 755
0=nothing
4=read
5=read / execute
6=read / write
7=read / write / execute

chown

change owner - Change the owner of a file

Dealing with Environment Variables

export =

Set and environment variable in teh current shell.

set

Show all of the current envireonment variables that have been exported

unset

Delete an environment variable

Power Users

df -k

Determine how full the partitions on the local hard disks are.

du -ks

Determine the disk usage of a given directory and all sub directories

find -name

Locate a file on the file system.

ps -ef

Get a look at the processes running on the machine

top

Take a look at the memory and CPU usage as well as the top processes on the machine

man

Get help for a given command

diff

Report the differences between two files.

gzip

Compress a file.

gunzip

Decompress a file.

tail

Look at the end of a file.

tar cf ./*

Tar all the files in this directory into a tar-ball in the lower directory

tar xvf

De-tar the contents of a tar-ball

Perl Specific

perl -w

Execute a Perl Script with warnings.

perl -c

Get compilation errors for a Perl script

perldoc ::

Get help for a Perl function in a given module.

perldoc perlfunc

Get help on basic Perl functions.

perldoc perlpod

Get help on Perl (POD = Plain Old Documentation) documentation

Java Specific

java

Run a compiled class

java -client

Run a compiled class where the JVM is optimized as a client

java -server

Run compiled class where the JVM is optimized as a server

javac

Compile a source file

Linux command websites

The first thing I learned about Linux command was actually bash script which makes life much easier. There are just simply too many commands to memorize. To have a cheat sheet posted near your desk is a great idea.

Some simple Linux commands

I am kind of person can't live without Windows. In short, I need AutoCAD almost everyday. But we only have a Windows version, and it is not cheap. When I run simulation codes, it seems to me that Linux is a better platform. So I go with dual boot.
The following are commands I use in Linux:

  • tar zcvf ***.tar.gz *** --to zip a folder or file with name ***
  • tar zxvf ***.tar.gz --to unzip a folder or file
  • ls -l --list contents
  • pwd --print directory
  • ps -aux --list processes
  • kill -9 *** --to kill a process name ***
  • sudo yum -y update --to update the whole system (I do this before I go home)
  • mv --rename or move file/folder
  • rm --remove file (to remove folder use rm -R)
  • man --this is a good friend

Some AutoCAD commands

The following are some commands I use in AutoCAD.

  • units --to setup units for your DWGs
  • layer --to organize your DWGs' layers
  • di --measure distance
  • center --center of circle
  • 3do --3D orbit for solid model watching
  • shade --solid color on 3D DWGs
  • from --starting point (when you draw a line)
  • @ --refer to the point you just selected (otherwise, CAD will refer to the origin)
  • < --drawing a line at an arbitrary angle. (When you're drawing a line at an unusual angle, you may want to see how the angle looks. After you specify the first point, you can type the < (angle) symbol and then the angle you want to try. For example, <10.
  • google is always there for the rest :-)