Logo

Basic linux commands

Posted under » Linux on 30 September 2009

A lot of things cannot be done unless you are SUDO

sudo su -

list directory
very similar to DIR command in windows

ls // basic
ls -a // show hidden files
ls -a | less // cleaner version of list show hidden files
ls -l // this will show the owner and group

Sometimes you might want linux to suggest or auto complete eg. cd commands. To do this, you use the TAB button.

If you want to look for old commands,

history | less
history | more
history | grep firefox

Grep btw is like search.

For more tips -> http://goo.gl/UGKpd

Sometimes you need to go ~/.somewhere/
This could mean 2 things. Either the root folder at /root/.somewhere or /home/yourname/.somewhere

Make directory

MKDIR newfile

Copy
Copies the contents of file1 into file2

cp file1 file2 

In some cases, it is preferable to use the "cp --preserve" option to maintain file permission etc.

cp -R -p fileori filecopy

You can combine text file into 1 using cat

cat *.txt > combined.txt

Move
Also known as rename

mv file1 file2 

Remove

The rm command deletes (removes) files and directories.

rm -r directory 

If files.

rm file1 file2 

Changing file ownership

chown you some_file 

Please see mac version.

The group ownership of a file or directory

chgrp new_group some_file

CHMOD

chmod 600 some_file -R
  • 600 - Only owner can read and write. The rest can't even read.
  • 644 - Only owner can write.
  • 664 - Most common. Owner and group can write
  • 666 - Everyone has write permission
  • 777 - Everyone can do anything they wish

PWD

Often it's useful to know your exact current directory. To find this out, type the command pwd (short for "print working directory")

find

find /usr -name 'file*'
find -name 'bazaar'
find -name bazaar

Find every file under the directory /usr starting in "file".
Can try also whereis.

Grep for finding strings.

Last but not least... creating soft link or alias.

Ok this is last for sure

shutdown -h now