Archiving and Searching Files

Archiving Commands

zip

  • zip - package and compress files into archives

    • zip files archive a number of files into a single file

    • zip compress the files so the archive takes less space

zip /tmp/backup-notes.zip words.txt words2.txt
ls -l /tmp/
	-rw-rw-r-- 1 user user  499 ago 28 20:11 backup-notes.zip
	
zip -r /tmp/backup-dirs.zip dir1 dir2
# -r option must be used to include the files in the sub-directories

unzip

  • unzip - list, test and extract compressed files in a zip archive

# List archive files without extracting anything.

unzip -l /tmp/backup-notes.zip
	Archive:  /tmp/backup-notes.zip
	  Length      Date    Time    Name
	---------  ---------- -----   ----
	      128  2022-08-28 19:27   words.txt
	       87  2022-08-28 19:35   words2.txt
	---------                     -------
	      215                     2 files

tar

  • tar - creates an archive file from multiple files and directories, without compression by default

    • supports a vast range of compression algorithms

    • .tar and .gz files are more commonly used in Linux than zip files.

gzip

  • gzip - compress or uncompress single files

    • is most often used to compress text files, .tar archives, and web pages.

    • by default, it keeps the original file timestamp, mode, ownership, and name in the compressed file.

Searching Commands

find

  • find - search for files in a directory hierarchy

    • a starting point for the search is necessary

locate

  • locate - find files by name, using a database

    • it can be faster than find command

which

  • which - locate a command

    • it displays the full path of the command with its associated name

whereis

  • whereis - locate the binary, source code and manual page for a command


Last updated

Was this helpful?