Viewing files

To view a file you can use cat, more, and less commands

cat will output to standard output which will be your screen, if its a big file cat will only show the end of the file.

cat textfile1

To see a file one page at a time use more or less commands

more textfile1

less textfile1

To edit a file you can use vi

vi textfile1

To view only the top 10 lines of a file

head -10 textfile1

Copying and moving files

Copy file1 and name it file2

cp /home/des/file1 file2

Copy recursively all files beginning with a . to the profiles.backup folder

cp -r .?*  profiles.backup

Move file1 to file2 , if file 2 does not exist file1 is just renamed to file2, if file2 does exist then file1 is moved to file2

mv /home/des/file1 file2

To move 3 files to a directory

mv file1 file2 file3 directory

Networking using arp, ssh, and scp

To list all machines in the address resolution table

arp -a

We can use the Secure Shell (SSH)  network protocol for secure data communication, remote command-line login, remote command execution. First make sure the service is running .

service sshd status

service sshd start

Make it run automatically

chkconfig sshd on

Add a user to another linux machine and ssh to that machine as that user

useradd -m des

Using Cron scheduler

Cron is a daemon that executes scheduled commands and is started automatically from /etc/init.d when multiuser run levels are started.

To list all cron jobs

crontab -l

To start a new crontab

crontab -e

Some systems will give you a choice of editor to edit the crontab file, if you want to set yours to a specific editor permanently type

export EDITOR=vi

And to set it for nano

export EDITOR=nano

Find out what version of SuSE linux you have

Linux versions are stored in the /etc directory under a file named XXXX-release where xxxx is the linux version e.g SuSE, Ubuntu etc. So just cat /etc/xxxx-release

cat /etc/SuSE-release

To find the correct file

ls -l /etc | grep .*-release

Backups and Archives using tar and gunzip

To make an archive we use the tar command which stands for tape archive. To make an archive of my home directory /home/des, cd to it and type

tar -cvf mytar.tar /home/des/

This will create the archive file mytar.tar in /home/des The -cvf stands for -c = create v = verbose and -f = file archive

To see a list of the contents of the tar file

tar -tvf /home/des/mytar.tar

To compress the tar file, cd  to the directory of the tar file and type

gzip  mytar.tar

Batch jobs using at

Change to root user in SuSE

su -

In ubuntu use sudo before every administrative task. To install packages inubuntu use sudo apt-get install packagename

sudo apt-get install atd

To schedule a task using at, first make sure you have the service running on you machine.

service atd status

If its not installed, for SuSE you use zypper

zypper in atd

If it's not running start the service

service atd start

Find files and directories

To find a file named hostname ignoring case and searching from /

find / -iname hostname

To find all files named zulu and redirect the output into a file named zulufind ignoring errors

find / -name Zulu>zulufind 2>/dev/null

To find a file from the current directory

find . -name passwd

To ignore errors add 2>/dev/null to the end where 2 means stderror and >/dev/null redirects to a null device (basically dumps the errors to nowhere)

Group Definitions

To add a group edit the /etc/group file

vi /etc/group



mkdir /home/mygroup

chgrp mygroup /home/mygroup
ls -ld /home/mygroup

Give the group write permission
chmod g+w /home/mygroup 

Turn on set group id on mygroup so all files created in it have group id permissions  

chmod g+s /home/mygroupman chmod

ls -ld /home/mygroup


To see a list of the processes running on your machine use the ps command. Pipe it into  more

ps -ef | more

To find all the processes running under user des

ps -ef | grep des

Top will provide a real time view of processes running with some summary infomation.


If you find a process you would like to terminate, say PID 2056 you can use the kill command.

kill 2056


Subscribe to RSS - linux-basic