Bash one liner – how to compress, move, and extract a directory Bash vienu starpliku - kā, lai saspiestu, pārvieto un ekstrakts katalogs

by Sukrit Dhandhania on May 8, 2009 by Sukrit Dhandhania 2009 8 Maijs,

Linux

The other day I needed to migrate a directory containing a lot of files from one location on my Linux server to another. Otro dienu man vajadzēja migrēt direktorija satur daudz failus no vienas vietas uz manu Linux servera uz citu. There are a number of ways I could do this. Ir veidos es varētu darīt šo numuru. Using a simple cp command could have done the trick. Izmantojot vienkāršu cp komanda varēja izdarīt triks. However, as the data I was copying was a database and I wanted to make sure that the copying was done perfectly, I looked on the Internet and found a brilliant one line bash solution for this. Tomēr, kā dati biju kopēšana ir datubāzē, un es gribēju pārliecināties, ka kopēšanas tika izdarīts perfekti, paskatījos uz internetā un konstatēja izcili vienas līnijas bash risinājums tam.

I wanted to move the contents of the directory /var/lib/mysql to /opt/mysql . Es gribēju, lai pārvietotos no kataloga saturs / var / lib / mysql uz / opt / mysql. First I changed to the directory /var/lib/mysql : Vispirms es mainīta uz direktoriju / var / lib / mysql:

# cd /var/lib/mysql # Cd / var / lib / mysql

Then I ran the following one liner to do the magic for me. Tad es skrēja pēc viena līnijpārvadātāju darīt burvju par mani.

# tar cf – * | ( cd /opt/mysql; tar xfp -) # Tar cf - * | (cd / opt / mysql, darva XFP -)

I used the command shown above to copy my database files. Es lieto komandu kā iepriekš norādīts, nokopēt savu datubāzi failus. What it does is it compresses the entire contents of the current directory, changes to the location of the destination directory ( /opt/mysql in this case), and then extracts the archive. Kas tas ir tas saspiež visu saturu no pašreizējā direktorijā, mainīt atrašanās vietu, mērķa direktoriju (/ opt / mysql šajā gadījumā), un tad ekstrakti arhīvā.

Related Posts: Related Posts:
  • How to create and extract zip, tar, tar.gz and tar.bz2 files in Linux Kā izveidot un iegūt zip, darva, tar.gz un tar.bz2 failus Linux
  • How to encrypt your Linux backups Kā lai šifrētu savu Linux backups
  • How to download files from the Linux command line Kā lejupielādēt failus no Linux komandrindas
  • How to get a list of files an RPM package depends on Kā nokļūt failu saraksts RPM paketi ir atkarīga no
  • Some useful Linux bash tricks Daži noderīgi Linux bash tricks
  • Get Simple Help tutorials just like this one in your email inbox every day - for free! Get Simple Palīdzība konsultācijas tāpat kā šo vienu savā e-pastā ik dienas - bez maksas! Just enter your email address below: Vienkārši ievadiet savu e-pasta adresi:

    You can always opt out of this email subscription at any time. Jūs vienmēr varat atteikties no šīs e-pasta abonementu jebkurā laikā.

    { 3 trackbacks } (3 trackbacks)

    More secure CLI file copy « Linux & Stuff Drošāku CLI faila kopiju «Linux & Stuff
    05.28.09 at 9:29 am 05.28.09 at 9:29
    How to setup slow query logging in MySQL | TuxWire : The Linux Blog Kā setup lēno vaicājumu piesakoties MySQL | TuxWire: Linux Blog
    09.22.09 at 6:03 am 09.22.09 at 6:03
    How to find all the empty files in a directory | TuxWire : The Linux Blog Kā atrast visu tukšo failus katalogs | TuxWire: Linux Blog
    09.25.09 at 11:02 am 09.25.09 at 11:02

    { 0 comments… (0 comments ... add one now pievienot vienu tagad } )

    Leave a Comment Leave Comment

    You can use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> Jūs varat izmantot šos HTML tagus un atribūtus: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>