copy /proc folder

2019-03-18 140 words 1 min read

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

Related Articles:


author

Authored By Amit Agarwal

Amit Agarwal, Linux and Photography are my hobbies.Creative Commons Attribution 4.0 International License.

We notice you're using an adblocker. If you like our webite please keep us running by whitelisting this site in your ad blocker. We’re serving quality, related ads only. Thank you!

I've whitelisted your website.

Not now
This website uses cookies to ensure you get the best experience on our website. Learn more Got it