copy /proc folder

2019-03-18 1 min read Bash Learning Linux

Other day, I was trying to copy the proc folder with following command:

tar cvzf /tmp/proc.tgz /proc

and I found out that all the files in tar were empty. Strange it may seem but lot of people are facing this as /proc is not a regular filesystem, so I wrote a quick script to copy the proc folder. Here is the script:

cd /
mkdir /tmp/proc
[[ -z $1 ]] && exit -1
find /proc/$1/ -not -name pagemap | while read F ; do
    D=/tmp/$F
    if [[ -d $F ]]
    then
        echo "$(ls -ld $F) => Directory"
        mkdir -p $D
    fi
    if [[ -L $F ]]
    then
        echo "$(ls -ld $F) => copied"
        cp -P $F /tmp/$F
        
    elif [[ -f $F ]]
    then
        echo "$(ls -ld $F) => Cat"
        cat $F > /tmp/$F
    else
        echo "Dont know $F"
    fi
done

Kill processes that have been running for more than a week

2010-02-04 1 min read Linux

<a href="http://blog.amit-agarwal.co.in/category/linux/">Bookmark this category

<span style="font-size: x-large;"><a href="http://feedproxy.google.com/~r/Command-line-fu/~3/kr_otvdAVxA/kill-processes-that-have-been-running-for-more-than-a-week">Kill processes that have been running for more than a week
$ find /proc -user myuser -maxdepth 1 -type d -mtime +7 -exec basename {} ; | xargs kill -9

  • <a href="http://www.commandlinefu.com/commands/view/3702/kill-processes-that-have-been-running-for-more-than-a-week">View this command to comment, vote or add to favourites
  • <a href="http://feeds2.feedburner.com/commands/by/sharfah">View all commands by <a href="http://feeds2.feedburner.com/commands/by/sharfah">sharfah

<a href="http://www.commandlinefu.com"><img src="http://blog.amit-agarwal.co.in/wp-content/uploads/2010/08/header-logo.jpg" alt="commandlinefu.com" align="bottom" />

by David Winterbottom (<a href="http://codeinthehole.com">codeinthehole.com)

<a href="http://feedads.g.doubleclick.net/~a/NeXCFRlIt7EM3A_bb4x2jLaegwk/0/da"><img src="http://blog.amit-agarwal.com/wp-content/uploads/amit-agarwal.co.in/~a/NeXCFRlIt7EM3A_bb4x2jLaegwk/0/di" border="0" alt="" align="bottom" />
<a href="http://feedads.g.doubleclick.net/~a/NeXCFRlIt7EM3A_bb4x2jLaegwk/1/da"><img src="http://blog.amit-agarwal.com/wp-content/uploads/amit-agarwal.co.in/~a/NeXCFRlIt7EM3A_bb4x2jLaegwk/1/di" border="0" alt="" align="bottom" />

Continue reading