Cara menggunakan filecmp python install

Python adalah bahasa pemrograman yang banyak digunakan, seperti php atau perl. Di dalamnya terdapat sejumlah library yang kompatibel dengan sebagian besar protokol internet. Oleh karena itu, ada baiknya server developer dilengkapi dengan fungsi ini.

Anda dapat menginstall aplikasi di Python dengan menggunakan pip. Pip sendiri merupakan tool manajemen aplikasi untuk Python. Di artikel ini, kami akan membahas cara install Python di Ubuntu 18.04.

Cara Install Python di Ubuntu

Sebelum menginstal aplikasi apa pun ke server atau menggunakan perangkat virtual Python, Anda perlu login terlebih dulu ke VPS server melalui SSH. Jika Anda lupa caranya, silakan baca tutorial PuTTY kami.

Langkah selanjutnya adalah memperbarui daftar aplikasi dengan menjalankan command di bawah ini. Tidak perlu role khusus untuk melakukannya. Anda bisa bertindak sebagai admin atau user biasa untuk menjalankan command berikut ini dengan perintah sudo. Tambahkan sudo ke command sebelum memroses update.

sudo apt update

Secara default, Python 3 telah terinstall di distribusi Linux Ubuntu 18.04. Untuk menginstall aplikasi python-pip, gunakan command di bawah ini yang juga akan mengaktifkan dependency yang dibutuhkan guna mempersingkat proses.

apt install python3-pip

Biasanya command Python ditujukan untuk Python 2.7 dan command Python 3 untuk versi 3 yang terbaru. Pada OS versi lama, instalasi defaultnya adalah Python 2.7. Prosedurnya kurang lebih sama untuk setiap versi.

Gunakan command di bawah ini untuk menginstall Python versi lama:

apt install python

Jika pip bisa dinstall di Python 3, maka Anda juga dapat install pip di Python versi lama dengan menggunakan command ini:

apt install python-pip

Masing-masing file di bawah ini diperuntukkan bagi dua versi Python dan pip:

/usr/bin/python /usr/bin/python3 /usr/bin/pip /usr/bin/pip3

Anda dapat memverifikasi masing-masing versi dengan menggunakan command pip di bawah ini:

pip --version

pip 9.0.1 dari /usr/lib/python2.7/dist-packages (python 2.7)

pip3 --version

pip 9.0.1 dari /usr/lib/python3/dist-packages (python 3.6)

python -V

Python 2.7.15rc1

python3 -V

Python 3.6.7

Install Python Ubuntu

Selanjutnya, Anda akan install Python dengan pip. Command yang digunakan bergantung pada versi Python yang diinstall. Untuk versi Python 2.7, gunakan pip, sedangkan Python 3.6, gunakan command pip3. Gambaran command line-nya dapat dilihat di bawah ini:

pip install PACKAGE_NAMEapt install python3-pip0

Sebagai contoh, kami akan menginstall scrapy ke perangkat.

apt install python3-pip1

Kesimpulan

Python merupakan bahasa pemrograman yang mudah digunakan dan user-friendly. Karena kemudahannya dalam bidang programming dan banyaknya ketersediaan library, Python menjadi favorit di kalangan developer.

Menurut GitHub ranking, Python merupakan bahasa pemrograman kedua yang paling banyak digunakan. Jika Anda adalah pengguna baru tapi sudah punya pengetahuan dasar tentang programming, maka tak ada salahnya untuk menggunakan bahasa pemrograman Python. Dan kini, melalui artikel ini, Anda sudah tahu cara install Python. Selamat mencoba!

Penulis

Nadia Agatha

Nadia merupakan penerjemah lepas sejak 2016, kini ia menjadi penerjemah untuk Hostinger. Ia gemar membaca dan melakukan penelitian seputar penerjemahan dan sosiolinguistik. Disamping itu, ia juga suka bermain dengan kucingnya dan bercengkrama bersama teman-temannya di waktu senggang.

The same directory structure is repeated one time under the “common_dir” directories to give interesting recursive comparison options.

Comparing Files

The filecmp module includes functions and a class for comparing files and directories on the filesystem. If you need to compare two files, use the cmp() function.

import filecmp print 'common_file:', print filecmp.cmp('example/dir1/common_file', 'example/dir2/common_file'), print filecmp.cmp('example/dir1/common_file', 'example/dir2/common_file', shallow=False) print 'not_the_same:', print filecmp.cmp('example/dir1/not_the_same', 'example/dir2/not_the_same'), print filecmp.cmp('example/dir1/not_the_same', 'example/dir2/not_the_same', shallow=False) print 'identical:', print filecmp.cmp('example/dir1/file_only_in_dir1', 'example/dir1/file_only_in_dir1'), print filecmp.cmp('example/dir1/file_only_in_dir1', 'example/dir1/file_only_in_dir1', shallow=False)

By default, cmp() looks only at the information available from os.stat(). The shallow argument tells cmp() whether to look at the contents of the file, as well. The default is to perform a shallow comparison, without looking inside the files. Notice that files of the same size created at the same time seem to be the same if their contents are not compared.

$ python filecmp_cmp.py common_file: True True not_the_same: True False identical: True True

To compare a set of files in two directories without recursing, use filecmp.cmpfiles(). The arguments are the names of the directories and a list of files to be checked in the two locations. The list of common files should contain only filenames (directories always result in a mismatch) and the files must be present in both locations. The code below shows a simple way to build the common list. If you have a shorter formula, post it in the comments. The comparison also takes the shallow flag, just as with cmp().

import filecmp import os # Determine the items that exist in both directories d1_contents = set(os.listdir('example/dir1')) d2_contents = set(os.listdir('example/dir2')) common = list(d1_contents & d2_contents) common_files = [ f for f in common if os.path.isfile(os.path.join('example/dir1', f)) ] print 'Common files:', common_files # Compare the directories match, mismatch, errors = filecmp.cmpfiles('example/dir1', 'example/dir2', common_files) print 'Match:', match print 'Mismatch:', mismatch print 'Errors:', errors

cmpfiles() returns three lists of filenames for files that match, files that do not match, and files that could not be compared (due to permission problems or for any other reason).

$ python filecmp_cmpfiles.py Common files: ['not_the_same', 'file_in_dir1', 'common_file'] Match: ['not_the_same', 'common_file'] Mismatch: ['file_in_dir1'] Errors: []

Using dircmp

The functions described above are suitable for relatively simple comparisons, but for recursive comparison of large directory trees or for more complete analysis, the dircmp class is more useful. In its simplest use case, you can print a report comparing two directories with the report() method:

import filecmp filecmp.dircmp('example/dir1', 'example/dir2').report()

The output is a plain-text report showing the results of just the contents of the directories given, without recursing. In this case, the file “not_the_same” is thought to be the same because the contents are not being compared. There is no way to have dircmp compare the contents of files like cmp() can.

$ python filecmp_dircmp_report.py diff example/dir1 example/dir2 Only in example/dir1 : ['dir_only_in_dir1', 'file_only_in_dir1'] Only in example/dir2 : ['dir_only_in_dir2', 'file_only_in_dir2'] Identical files : ['common_file', 'not_the_same'] Common subdirectories : ['common_dir'] Common funny cases : ['file_in_dir1']

For more detail, and a recursive comparison, use report_full_closure():

import filecmp filecmp.dircmp('example/dir1', 'example/dir2').report_full_closure()

The output includes comparisons of all parallel subdirectories.

$ python filecmp_dircmp_report_full_closure.py diff example/dir1 example/dir2 Only in example/dir1 : ['dir_only_in_dir1', 'file_only_in_dir1'] Only in example/dir2 : ['dir_only_in_dir2', 'file_only_in_dir2'] Identical files : ['common_file', 'not_the_same'] Common subdirectories : ['common_dir'] Common funny cases : ['file_in_dir1'] diff example/dir1/common_dir example/dir2/common_dir Common subdirectories : ['dir1', 'dir2'] diff example/dir1/common_dir/dir2 example/dir2/common_dir/dir2 Identical files : ['common_file', 'file_only_in_dir2', 'not_the_same'] Common subdirectories : ['common_dir', 'dir_only_in_dir2', 'file_in_dir1'] diff example/dir1/common_dir/dir2/common_dir example/dir2/common_dir/dir2/common_dir diff example/dir1/common_dir/dir2/dir_only_in_dir2 example/dir2/common_dir/dir2/dir_only_in_dir2 diff example/dir1/common_dir/dir2/file_in_dir1 example/dir2/common_dir/dir2/file_in_dir1 diff example/dir1/common_dir/dir1 example/dir2/common_dir/dir1 Identical files : ['common_file', 'file_in_dir1', 'file_only_in_dir1', 'not_the_same'] Common subdirectories : ['common_dir', 'dir_only_in_dir1'] diff example/dir1/common_dir/dir1/common_dir example/dir2/common_dir/dir1/common_dir diff example/dir1/common_dir/dir1/dir_only_in_dir1 example/dir2/common_dir/dir1/dir_only_in_dir1

Using differences in your program

Besides producing printed reports, dircmp calculates useful lists of files you can use in your programs directly. Each of the following attributes is calculated only when requested, so instantiating a dircmp does not incur a lot of extra overhead.

The files and subdirectories contained in the directories being compared are listed in left_list and right_list:

$ ls -Rlast example total 0 0 drwxr-xr-x 4 dhellmann dhellmann 136 Apr 20 17:04 . 0 drwxr-xr-x 9 dhellmann dhellmann 306 Apr 20 17:04 .. 0 drwxr-xr-x 8 dhellmann dhellmann 272 Apr 20 17:04 dir1 0 drwxr-xr-x 8 dhellmann dhellmann 272 Apr 20 17:04 dir2 example/dir1: total 32 0 drwxr-xr-x 8 dhellmann dhellmann 272 Apr 20 17:04 . 0 drwxr-xr-x 4 dhellmann dhellmann 136 Apr 20 17:04 .. 0 drwxr-xr-x 2 dhellmann dhellmann 68 Apr 20 17:04 common_dir 8 -rw-r--r-- 1 dhellmann dhellmann 21 Apr 20 17:04 common_file 0 drwxr-xr-x 2 dhellmann dhellmann 68 Apr 20 17:04 dir_only_in_dir1 8 -rw-r--r-- 1 dhellmann dhellmann 22 Apr 20 17:04 file_in_dir1 8 -rw-r--r-- 1 dhellmann dhellmann 22 Apr 20 17:04 file_only_in_dir1 8 -rw-r--r-- 1 dhellmann dhellmann 17 Apr 20 17:04 not_the_same example/dir2: total 24 0 drwxr-xr-x 8 dhellmann dhellmann 272 Apr 20 17:04 . 0 drwxr-xr-x 4 dhellmann dhellmann 136 Apr 20 17:04 .. 0 drwxr-xr-x 2 dhellmann dhellmann 68 Apr 20 17:04 common_dir 8 -rw-r--r-- 1 dhellmann dhellmann 21 Apr 20 17:04 common_file 0 drwxr-xr-x 2 dhellmann dhellmann 68 Apr 20 17:04 dir_only_in_dir2 0 drwxr-xr-x 2 dhellmann dhellmann 68 Apr 20 17:04 file_in_dir1 8 -rw-r--r-- 1 dhellmann dhellmann 22 Apr 20 17:04 file_only_in_dir2 8 -rw-r--r-- 1 dhellmann dhellmann 17 Apr 20 17:04 not_the_same 0

$ ls -Rlast example total 0 0 drwxr-xr-x 4 dhellmann dhellmann 136 Apr 20 17:04 . 0 drwxr-xr-x 9 dhellmann dhellmann 306 Apr 20 17:04 .. 0 drwxr-xr-x 8 dhellmann dhellmann 272 Apr 20 17:04 dir1 0 drwxr-xr-x 8 dhellmann dhellmann 272 Apr 20 17:04 dir2 example/dir1: total 32 0 drwxr-xr-x 8 dhellmann dhellmann 272 Apr 20 17:04 . 0 drwxr-xr-x 4 dhellmann dhellmann 136 Apr 20 17:04 .. 0 drwxr-xr-x 2 dhellmann dhellmann 68 Apr 20 17:04 common_dir 8 -rw-r--r-- 1 dhellmann dhellmann 21 Apr 20 17:04 common_file 0 drwxr-xr-x 2 dhellmann dhellmann 68 Apr 20 17:04 dir_only_in_dir1 8 -rw-r--r-- 1 dhellmann dhellmann 22 Apr 20 17:04 file_in_dir1 8 -rw-r--r-- 1 dhellmann dhellmann 22 Apr 20 17:04 file_only_in_dir1 8 -rw-r--r-- 1 dhellmann dhellmann 17 Apr 20 17:04 not_the_same example/dir2: total 24 0 drwxr-xr-x 8 dhellmann dhellmann 272 Apr 20 17:04 . 0 drwxr-xr-x 4 dhellmann dhellmann 136 Apr 20 17:04 .. 0 drwxr-xr-x 2 dhellmann dhellmann 68 Apr 20 17:04 common_dir 8 -rw-r--r-- 1 dhellmann dhellmann 21 Apr 20 17:04 common_file 0 drwxr-xr-x 2 dhellmann dhellmann 68 Apr 20 17:04 dir_only_in_dir2 0 drwxr-xr-x 2 dhellmann dhellmann 68 Apr 20 17:04 file_in_dir1 8 -rw-r--r-- 1 dhellmann dhellmann 22 Apr 20 17:04 file_only_in_dir2 8 -rw-r--r-- 1 dhellmann dhellmann 17 Apr 20 17:04 not_the_same 1

The inputs can be filtered by passing a list of names to ignore to the constructor. By default the names RCS, CVS, and tags are ignored.

$ ls -Rlast example total 0 0 drwxr-xr-x 4 dhellmann dhellmann 136 Apr 20 17:04 . 0 drwxr-xr-x 9 dhellmann dhellmann 306 Apr 20 17:04 .. 0 drwxr-xr-x 8 dhellmann dhellmann 272 Apr 20 17:04 dir1 0 drwxr-xr-x 8 dhellmann dhellmann 272 Apr 20 17:04 dir2 example/dir1: total 32 0 drwxr-xr-x 8 dhellmann dhellmann 272 Apr 20 17:04 . 0 drwxr-xr-x 4 dhellmann dhellmann 136 Apr 20 17:04 .. 0 drwxr-xr-x 2 dhellmann dhellmann 68 Apr 20 17:04 common_dir 8 -rw-r--r-- 1 dhellmann dhellmann 21 Apr 20 17:04 common_file 0 drwxr-xr-x 2 dhellmann dhellmann 68 Apr 20 17:04 dir_only_in_dir1 8 -rw-r--r-- 1 dhellmann dhellmann 22 Apr 20 17:04 file_in_dir1 8 -rw-r--r-- 1 dhellmann dhellmann 22 Apr 20 17:04 file_only_in_dir1 8 -rw-r--r-- 1 dhellmann dhellmann 17 Apr 20 17:04 not_the_same example/dir2: total 24 0 drwxr-xr-x 8 dhellmann dhellmann 272 Apr 20 17:04 . 0 drwxr-xr-x 4 dhellmann dhellmann 136 Apr 20 17:04 .. 0 drwxr-xr-x 2 dhellmann dhellmann 68 Apr 20 17:04 common_dir 8 -rw-r--r-- 1 dhellmann dhellmann 21 Apr 20 17:04 common_file 0 drwxr-xr-x 2 dhellmann dhellmann 68 Apr 20 17:04 dir_only_in_dir2 0 drwxr-xr-x 2 dhellmann dhellmann 68 Apr 20 17:04 file_in_dir1 8 -rw-r--r-- 1 dhellmann dhellmann 22 Apr 20 17:04 file_only_in_dir2 8 -rw-r--r-- 1 dhellmann dhellmann 17 Apr 20 17:04 not_the_same 2

In this case, the “common_file” is left out of the list of files to be compared.

$ ls -Rlast example total 0 0 drwxr-xr-x 4 dhellmann dhellmann 136 Apr 20 17:04 . 0 drwxr-xr-x 9 dhellmann dhellmann 306 Apr 20 17:04 .. 0 drwxr-xr-x 8 dhellmann dhellmann 272 Apr 20 17:04 dir1 0 drwxr-xr-x 8 dhellmann dhellmann 272 Apr 20 17:04 dir2 example/dir1: total 32 0 drwxr-xr-x 8 dhellmann dhellmann 272 Apr 20 17:04 . 0 drwxr-xr-x 4 dhellmann dhellmann 136 Apr 20 17:04 .. 0 drwxr-xr-x 2 dhellmann dhellmann 68 Apr 20 17:04 common_dir 8 -rw-r--r-- 1 dhellmann dhellmann 21 Apr 20 17:04 common_file 0 drwxr-xr-x 2 dhellmann dhellmann 68 Apr 20 17:04 dir_only_in_dir1 8 -rw-r--r-- 1 dhellmann dhellmann 22 Apr 20 17:04 file_in_dir1 8 -rw-r--r-- 1 dhellmann dhellmann 22 Apr 20 17:04 file_only_in_dir1 8 -rw-r--r-- 1 dhellmann dhellmann 17 Apr 20 17:04 not_the_same example/dir2: total 24 0 drwxr-xr-x 8 dhellmann dhellmann 272 Apr 20 17:04 . 0 drwxr-xr-x 4 dhellmann dhellmann 136 Apr 20 17:04 .. 0 drwxr-xr-x 2 dhellmann dhellmann 68 Apr 20 17:04 common_dir 8 -rw-r--r-- 1 dhellmann dhellmann 21 Apr 20 17:04 common_file 0 drwxr-xr-x 2 dhellmann dhellmann 68 Apr 20 17:04 dir_only_in_dir2 0 drwxr-xr-x 2 dhellmann dhellmann 68 Apr 20 17:04 file_in_dir1 8 -rw-r--r-- 1 dhellmann dhellmann 22 Apr 20 17:04 file_only_in_dir2 8 -rw-r--r-- 1 dhellmann dhellmann 17 Apr 20 17:04 not_the_same 3

The set of files common to both input directories is maintained in common, and the files unique to each directory are listed in left_only, and right_only.

$ ls -Rlast example total 0 0 drwxr-xr-x 4 dhellmann dhellmann 136 Apr 20 17:04 . 0 drwxr-xr-x 9 dhellmann dhellmann 306 Apr 20 17:04 .. 0 drwxr-xr-x 8 dhellmann dhellmann 272 Apr 20 17:04 dir1 0 drwxr-xr-x 8 dhellmann dhellmann 272 Apr 20 17:04 dir2 example/dir1: total 32 0 drwxr-xr-x 8 dhellmann dhellmann 272 Apr 20 17:04 . 0 drwxr-xr-x 4 dhellmann dhellmann 136 Apr 20 17:04 .. 0 drwxr-xr-x 2 dhellmann dhellmann 68 Apr 20 17:04 common_dir 8 -rw-r--r-- 1 dhellmann dhellmann 21 Apr 20 17:04 common_file 0 drwxr-xr-x 2 dhellmann dhellmann 68 Apr 20 17:04 dir_only_in_dir1 8 -rw-r--r-- 1 dhellmann dhellmann 22 Apr 20 17:04 file_in_dir1 8 -rw-r--r-- 1 dhellmann dhellmann 22 Apr 20 17:04 file_only_in_dir1 8 -rw-r--r-- 1 dhellmann dhellmann 17 Apr 20 17:04 not_the_same example/dir2: total 24 0 drwxr-xr-x 8 dhellmann dhellmann 272 Apr 20 17:04 . 0 drwxr-xr-x 4 dhellmann dhellmann 136 Apr 20 17:04 .. 0 drwxr-xr-x 2 dhellmann dhellmann 68 Apr 20 17:04 common_dir 8 -rw-r--r-- 1 dhellmann dhellmann 21 Apr 20 17:04 common_file 0 drwxr-xr-x 2 dhellmann dhellmann 68 Apr 20 17:04 dir_only_in_dir2 0 drwxr-xr-x 2 dhellmann dhellmann 68 Apr 20 17:04 file_in_dir1 8 -rw-r--r-- 1 dhellmann dhellmann 22 Apr 20 17:04 file_only_in_dir2 8 -rw-r--r-- 1 dhellmann dhellmann 17 Apr 20 17:04 not_the_same 4

$ ls -Rlast example total 0 0 drwxr-xr-x 4 dhellmann dhellmann 136 Apr 20 17:04 . 0 drwxr-xr-x 9 dhellmann dhellmann 306 Apr 20 17:04 .. 0 drwxr-xr-x 8 dhellmann dhellmann 272 Apr 20 17:04 dir1 0 drwxr-xr-x 8 dhellmann dhellmann 272 Apr 20 17:04 dir2 example/dir1: total 32 0 drwxr-xr-x 8 dhellmann dhellmann 272 Apr 20 17:04 . 0 drwxr-xr-x 4 dhellmann dhellmann 136 Apr 20 17:04 .. 0 drwxr-xr-x 2 dhellmann dhellmann 68 Apr 20 17:04 common_dir 8 -rw-r--r-- 1 dhellmann dhellmann 21 Apr 20 17:04 common_file 0 drwxr-xr-x 2 dhellmann dhellmann 68 Apr 20 17:04 dir_only_in_dir1 8 -rw-r--r-- 1 dhellmann dhellmann 22 Apr 20 17:04 file_in_dir1 8 -rw-r--r-- 1 dhellmann dhellmann 22 Apr 20 17:04 file_only_in_dir1 8 -rw-r--r-- 1 dhellmann dhellmann 17 Apr 20 17:04 not_the_same example/dir2: total 24 0 drwxr-xr-x 8 dhellmann dhellmann 272 Apr 20 17:04 . 0 drwxr-xr-x 4 dhellmann dhellmann 136 Apr 20 17:04 .. 0 drwxr-xr-x 2 dhellmann dhellmann 68 Apr 20 17:04 common_dir 8 -rw-r--r-- 1 dhellmann dhellmann 21 Apr 20 17:04 common_file 0 drwxr-xr-x 2 dhellmann dhellmann 68 Apr 20 17:04 dir_only_in_dir2 0 drwxr-xr-x 2 dhellmann dhellmann 68 Apr 20 17:04 file_in_dir1 8 -rw-r--r-- 1 dhellmann dhellmann 22 Apr 20 17:04 file_only_in_dir2 8 -rw-r--r-- 1 dhellmann dhellmann 17 Apr 20 17:04 not_the_same 5

The common members can be further broken down into files, directories and “funny” items (anything that has a different type in the two directories or where there is an error from os.stat()).

$ ls -Rlast example total 0 0 drwxr-xr-x 4 dhellmann dhellmann 136 Apr 20 17:04 . 0 drwxr-xr-x 9 dhellmann dhellmann 306 Apr 20 17:04 .. 0 drwxr-xr-x 8 dhellmann dhellmann 272 Apr 20 17:04 dir1 0 drwxr-xr-x 8 dhellmann dhellmann 272 Apr 20 17:04 dir2 example/dir1: total 32 0 drwxr-xr-x 8 dhellmann dhellmann 272 Apr 20 17:04 . 0 drwxr-xr-x 4 dhellmann dhellmann 136 Apr 20 17:04 .. 0 drwxr-xr-x 2 dhellmann dhellmann 68 Apr 20 17:04 common_dir 8 -rw-r--r-- 1 dhellmann dhellmann 21 Apr 20 17:04 common_file 0 drwxr-xr-x 2 dhellmann dhellmann 68 Apr 20 17:04 dir_only_in_dir1 8 -rw-r--r-- 1 dhellmann dhellmann 22 Apr 20 17:04 file_in_dir1 8 -rw-r--r-- 1 dhellmann dhellmann 22 Apr 20 17:04 file_only_in_dir1 8 -rw-r--r-- 1 dhellmann dhellmann 17 Apr 20 17:04 not_the_same example/dir2: total 24 0 drwxr-xr-x 8 dhellmann dhellmann 272 Apr 20 17:04 . 0 drwxr-xr-x 4 dhellmann dhellmann 136 Apr 20 17:04 .. 0 drwxr-xr-x 2 dhellmann dhellmann 68 Apr 20 17:04 common_dir 8 -rw-r--r-- 1 dhellmann dhellmann 21 Apr 20 17:04 common_file 0 drwxr-xr-x 2 dhellmann dhellmann 68 Apr 20 17:04 dir_only_in_dir2 0 drwxr-xr-x 2 dhellmann dhellmann 68 Apr 20 17:04 file_in_dir1 8 -rw-r--r-- 1 dhellmann dhellmann 22 Apr 20 17:04 file_only_in_dir2 8 -rw-r--r-- 1 dhellmann dhellmann 17 Apr 20 17:04 not_the_same 6

In the example data, the item named “file_in_dir1” is a file in one directory and a subdirectory in the other, so it shows up in the “funny” list.

$ ls -Rlast example total 0 0 drwxr-xr-x 4 dhellmann dhellmann 136 Apr 20 17:04 . 0 drwxr-xr-x 9 dhellmann dhellmann 306 Apr 20 17:04 .. 0 drwxr-xr-x 8 dhellmann dhellmann 272 Apr 20 17:04 dir1 0 drwxr-xr-x 8 dhellmann dhellmann 272 Apr 20 17:04 dir2 example/dir1: total 32 0 drwxr-xr-x 8 dhellmann dhellmann 272 Apr 20 17:04 . 0 drwxr-xr-x 4 dhellmann dhellmann 136 Apr 20 17:04 .. 0 drwxr-xr-x 2 dhellmann dhellmann 68 Apr 20 17:04 common_dir 8 -rw-r--r-- 1 dhellmann dhellmann 21 Apr 20 17:04 common_file 0 drwxr-xr-x 2 dhellmann dhellmann 68 Apr 20 17:04 dir_only_in_dir1 8 -rw-r--r-- 1 dhellmann dhellmann 22 Apr 20 17:04 file_in_dir1 8 -rw-r--r-- 1 dhellmann dhellmann 22 Apr 20 17:04 file_only_in_dir1 8 -rw-r--r-- 1 dhellmann dhellmann 17 Apr 20 17:04 not_the_same example/dir2: total 24 0 drwxr-xr-x 8 dhellmann dhellmann 272 Apr 20 17:04 . 0 drwxr-xr-x 4 dhellmann dhellmann 136 Apr 20 17:04 .. 0 drwxr-xr-x 2 dhellmann dhellmann 68 Apr 20 17:04 common_dir 8 -rw-r--r-- 1 dhellmann dhellmann 21 Apr 20 17:04 common_file 0 drwxr-xr-x 2 dhellmann dhellmann 68 Apr 20 17:04 dir_only_in_dir2 0 drwxr-xr-x 2 dhellmann dhellmann 68 Apr 20 17:04 file_in_dir1 8 -rw-r--r-- 1 dhellmann dhellmann 22 Apr 20 17:04 file_only_in_dir2 8 -rw-r--r-- 1 dhellmann dhellmann 17 Apr 20 17:04 not_the_same 7

The differences between files are broken down similarly:

$ ls -Rlast example total 0 0 drwxr-xr-x 4 dhellmann dhellmann 136 Apr 20 17:04 . 0 drwxr-xr-x 9 dhellmann dhellmann 306 Apr 20 17:04 .. 0 drwxr-xr-x 8 dhellmann dhellmann 272 Apr 20 17:04 dir1 0 drwxr-xr-x 8 dhellmann dhellmann 272 Apr 20 17:04 dir2 example/dir1: total 32 0 drwxr-xr-x 8 dhellmann dhellmann 272 Apr 20 17:04 . 0 drwxr-xr-x 4 dhellmann dhellmann 136 Apr 20 17:04 .. 0 drwxr-xr-x 2 dhellmann dhellmann 68 Apr 20 17:04 common_dir 8 -rw-r--r-- 1 dhellmann dhellmann 21 Apr 20 17:04 common_file 0 drwxr-xr-x 2 dhellmann dhellmann 68 Apr 20 17:04 dir_only_in_dir1 8 -rw-r--r-- 1 dhellmann dhellmann 22 Apr 20 17:04 file_in_dir1 8 -rw-r--r-- 1 dhellmann dhellmann 22 Apr 20 17:04 file_only_in_dir1 8 -rw-r--r-- 1 dhellmann dhellmann 17 Apr 20 17:04 not_the_same example/dir2: total 24 0 drwxr-xr-x 8 dhellmann dhellmann 272 Apr 20 17:04 . 0 drwxr-xr-x 4 dhellmann dhellmann 136 Apr 20 17:04 .. 0 drwxr-xr-x 2 dhellmann dhellmann 68 Apr 20 17:04 common_dir 8 -rw-r--r-- 1 dhellmann dhellmann 21 Apr 20 17:04 common_file 0 drwxr-xr-x 2 dhellmann dhellmann 68 Apr 20 17:04 dir_only_in_dir2 0 drwxr-xr-x 2 dhellmann dhellmann 68 Apr 20 17:04 file_in_dir1 8 -rw-r--r-- 1 dhellmann dhellmann 22 Apr 20 17:04 file_only_in_dir2 8 -rw-r--r-- 1 dhellmann dhellmann 17 Apr 20 17:04 not_the_same 8

Remember, the file “not_the_same” is only being compared via os.stat, and the contents are not examined.

$ ls -Rlast example total 0 0 drwxr-xr-x 4 dhellmann dhellmann 136 Apr 20 17:04 . 0 drwxr-xr-x 9 dhellmann dhellmann 306 Apr 20 17:04 .. 0 drwxr-xr-x 8 dhellmann dhellmann 272 Apr 20 17:04 dir1 0 drwxr-xr-x 8 dhellmann dhellmann 272 Apr 20 17:04 dir2 example/dir1: total 32 0 drwxr-xr-x 8 dhellmann dhellmann 272 Apr 20 17:04 . 0 drwxr-xr-x 4 dhellmann dhellmann 136 Apr 20 17:04 .. 0 drwxr-xr-x 2 dhellmann dhellmann 68 Apr 20 17:04 common_dir 8 -rw-r--r-- 1 dhellmann dhellmann 21 Apr 20 17:04 common_file 0 drwxr-xr-x 2 dhellmann dhellmann 68 Apr 20 17:04 dir_only_in_dir1 8 -rw-r--r-- 1 dhellmann dhellmann 22 Apr 20 17:04 file_in_dir1 8 -rw-r--r-- 1 dhellmann dhellmann 22 Apr 20 17:04 file_only_in_dir1 8 -rw-r--r-- 1 dhellmann dhellmann 17 Apr 20 17:04 not_the_same example/dir2: total 24 0 drwxr-xr-x 8 dhellmann dhellmann 272 Apr 20 17:04 . 0 drwxr-xr-x 4 dhellmann dhellmann 136 Apr 20 17:04 .. 0 drwxr-xr-x 2 dhellmann dhellmann 68 Apr 20 17:04 common_dir 8 -rw-r--r-- 1 dhellmann dhellmann 21 Apr 20 17:04 common_file 0 drwxr-xr-x 2 dhellmann dhellmann 68 Apr 20 17:04 dir_only_in_dir2 0 drwxr-xr-x 2 dhellmann dhellmann 68 Apr 20 17:04 file_in_dir1 8 -rw-r--r-- 1 dhellmann dhellmann 22 Apr 20 17:04 file_only_in_dir2 8 -rw-r--r-- 1 dhellmann dhellmann 17 Apr 20 17:04 not_the_same 9

Finally, the subdirectories are also mapped to new dircmp objects in the attribute subdirs to allow easy recursive comparison.

Postingan terbaru

LIHAT SEMUA