User Tools

Site Tools


linux:linux_general

General Linux Tips

Rsync over ssh

For some reason i couldn't use scp for file transfers on one of my machines.
But i really needed the config files i saved on another machine.
So heres a way to get files with rsync over ssh

$ rsync -avz -e ssh remoteuser@remotehost:/remote/dir /this/dir/

Background Jobs

To start a job in the background add & at the end:

grep -ril 'foo' * &

To list your running jobs:

[root@pdc etc]# jobs -l
[1]+  3195 Running

To bring a job to the foreground use fg

fg $jobid
[root@pdc etc]# fg 1

Downloading a Webpage recursively

wget --recursive --no-parent --domains tldp.org --page-requisites --convert-links --no-clobber http://commons.oreilly.com/wiki/index.php/Linux_in_a_Windows_World/
Switch Effect
–recursive Downloads ./* recursively
–no-parent No ../.
–domains Make sure that wget doesn't follow links from other domains
–page-requisites get all the elements that compose the page (images, CSS and so on).
–convert-links convert links so that they work locally, off-line.
–no-clobber don't overwrite any existing files (used in case the download is interrupted and resumed).

Extracting archives

tar xvzf target.tar.gz
tar cvzf target.tar.gz /home/somefile_or_folder

More to come!

Copying USB Sticks with DD

Make sure the affected devices aren't mounted.
In Example:

umount /media/VOLUME

After that you can just copy Device 1 on Device 2

dd if=/dev/sda of=/dev/sdb

ls options

(~/scripts) skull@dc:$ ls -lisah
total 96K
54173771 4.0K drwxr-xr-x   3 skull users 4.0K Nov 14 11:40 .
54173697 4.0K drwx------. 11 skull users 4.0K Nov 11 17:58 ..
54173782 4.0K -rwxrwx---   1 skull users 1009 Aug 21 19:21 auth.sh
54173773 4.0K -rwxrwx---   1 skull users 1.3K Aug 28 20:19 bridge_builder.sh
54173779 4.0K -rwxr-x---   1 skull users  945 Aug 21 19:54 debby.sh
(~/scripts) skull@dc:$ ls -laRZ
./physio_scripts:
total 16K
drwxr-xr-x skull users ?                                .
drwxr-xr-x skull users ?                                ..
drwxr-xr-x skull users ?                                new_scripts
drwxr-xr-x skull users ?                                old_scripts

mounting cifs drives through fstab

Example fstab:

# 
# /etc/fstab: static file system information
#
# <file system>        <dir>         <type>    <options>          <dump> <pass>
devpts                 /dev/pts      devpts    defaults            0      0
shm                    /dev/shm      tmpfs     nodev,nosuid        0      0
 
#/dev/cdrom             /media/cd   auto    ro,user,noauto,unhide   0      0
#/dev/dvd               /media/dvd  auto    ro,user,noauto,unhide   0      0
#/dev/fd0               /media/fl   auto    user,noauto             0      0
 
/dev/sda1 /boot ext2 defaults 0 1
/dev/sda2 / ext3 defaults 0 1
/dev/sda3 swap swap defaults 0 0
/dev/sda4 /home ext3 defaults 0 1
//diskstation/skull /mnt/skull cifs users,auto,username=skull,password=yourpassword,noexec,noperm 0 0
set:/mnt/fbase/public /public nfs defaults 0 1

followed by a

mount -a

Who uses what?

lsof - list open files

This shows you i.e. which user is using your external harddrive

lsof | grep /mnt/exthd

Using lsof without any options just display all the files in use.

awk example(s)

Without awk:

(~) skull@dc:$ chkconfig --list | grep ^mysql
mysqld          0:off   1:off   2:off   3:off   4:off   5:off   6:off

With awk:

(~) skull@dc:$ chkconfig --list | grep ^mysql | awk '{print $1}'
mysqld

Change the print $1 statement to view other columns!

(~) skull@dc:$ chkconfig --list | grep ^mysql | awk '{print $2}'
0:off

ToDo

find / grep options

Search for a filename:

(~) skull@dc:$ find . -name '*foo*'

Search a string inside of files

(~) skull@dc:$ grep -ril 'searchstring' *

More grep/find tips: Peters Blog

create dummy files

See here
skull 2011/05/16 23:45 Added some grammar corrections

linux/linux_general.txt · Last modified: 2013/02/12 10:39 by skull@darktemple.ch