Share to: share facebook share twitter share wa share telegram print page

Mv (Unix)

mv
Original author(s)Ken Thompson, Dennis Ritchie
(AT&T Bell Laboratories)
Developer(s)Various open-source and commercial developers
Initial releaseNovember 3, 1971; 52 years ago (1971-11-03)
Operating systemUnix, Unix-like, Inferno, IBM i
PlatformCross-platform
TypeCommand
Licensecoreutils: GPLv3

mv is a Unix command that moves one or more files or directories from one place to another. If both filenames are on the same filesystem, this results in a simple file rename; otherwise the file content is copied to the new location and the old file is removed. Using mv requires the user to have write permission for the directories the file will move between. This is because mv changes the content of both directories (i.e., the source and the target) involved in the move. When using the mv command on files located on the same filesystem, the file's timestamp is not updated.

On UNIX implementations derived from AT&T UNIX, cp, ln and mv are implemented as a single program with hard-linked binaries. The behavior is selected from the path name argv[0]. This is a common technique by which closely related commands that have been packaged as a unit allow the user to specify the particular course of the intended action.

History

A move command that moves a directory entry to a new directory was first implemented within Multics. It can be contracted to mv.[1] Later, the mv command appeared in Version 1 Unix[2] and became part of the X/Open Portability Guide issue 2 of 1987.[3] The version of mv bundled in GNU coreutils was written by Mike Parker, David MacKenzie, and Jim Meyering.[4] The command is available as a separate package for Microsoft Windows as part of the UnxUtils collection of native Win32 ports of common GNU Unix-like utilities.[5] The mv command has also been ported to the IBM i operating system.[6]

Conflicting existing file

When a filename is moved to an existing filename, the existing file is deleted (clobbered) by default. If the existing file is not writable but is in a directory that is writable, the mv command asks for confirmation (if run from a terminal) before proceeding, unless the -f (force) option is used.

Accidental overwriting can be prevented using the GNU -n (long format: --no-clobber) flag. Alternatively, -u (--update) only overwrites destination files that are older than source files, -i (--interactive) asks for confirmation upon each name conflict, and -b (--backup) renames target files out of the way.

A related ambiguity arises when a filename is moved to an existing directory. By default, mv would handle this as one trying to move a name inside this directory. GNU mv has a -T switch for disabling this assumption and try to overwrite the directory instead. An inverse -t makes the move-to-directory operation explicit.[4]

Moving versus copying and removing

Moving files within the same file system is generally implemented differently than copying the file and then removing the original. On platforms that do not support the rename syscall, a new link is added to the new directory and the original one is deleted. The data of the file is not accessed. All POSIX-conformant systems implement the rename call.

An actual move (effectively a rename) is dramatically faster than the circuitous copy-and-move procedure. The file's i-number (short for "inode number") does not change. No permission is required to read the file being moved insofar as—conceptually speaking—it is only cataloguing information that is being changed as a result of the "move." Since the source and target directories are being modified, to wit, entries are being created within the target directory and erased from within the source directory, "write" permission in both directories is required to complete the move. Moving files from one file system to another may fail entirely or may be automatically performed as an atomic copy-and-delete action; the actual details are dependent upon the implementation.

Moving a directory from one parent to a different parent directory requires write permission in the directory being moved, in addition to permissions to modify the old and new parents. This is because the i-number for the directory entry ".." (which can be used in any context as an alias for the parent of the current directory) changes as a result of the rename.

Options

Most versions of mv support:

  • -i interactively process, write a prompt to standard error before moving a file that would overwrite an existing file. If the response from the standard input begins with the character 'y' or 'Y', the move is attempted. (Overrides previous -f option.)
  • -f force overwriting the destination (overrides previous -i option).

These options are a part of X/Open Portability Guidelines, later the basis of POSIX and SUS. All POSIX-compliant mv implementations must support these.[7]

Examples

Command Explanation
mv myfile mynewfilename renames 'myfile' to 'mynewfilename'.
mv myfile subdir/myfile moves 'myfile' to 'subdir/myfile' relative to the current directory
mv myfile subdir same as the previous command, filename is implied to be the same
mv be.03 /mnt/bkup/bes copies 'be.03' to the 'bes' directory of the mounted volume 'bkup', then 'be.03' is removed
mv be.03/* /mnt/bkup/bes Same as above, except each file moved out of be.03 is deleted individually instead of all being deleted at once after the entire copying is finished.
mv afile another mydir moves multiple files to directory 'mydir'
mv /var/log/*z ~/logs This takes longer than expected if '/var' is on a different file system, as it frequently is, since files will be copied and deleted. The shell expands ~ to the user's home directory and treats * as a wildcard character.

Note that, in the above example, /mnt referred to the directory (the "mount point") over which a given file system is mounted. Naming such directories /mnt is a popular convention but is by no means necessary. A "file system" can be thought of as an independent tree that is logically regarded as a unit; its root is "mounted" atop a directory of the administrator's choice. Any previous contents of that directory are invisible, but they are "restored" when the new volume is unmounted.

See also

References

  1. ^ Multics Commands
  2. ^ mv(1) – FreeBSD General Commands Manual
  3. ^ mv: move files – Shell and Utilities Reference, The Single UNIX Specification, Version 4 from The Open Group
  4. ^ a b mv(1) – Linux General Commands Manual
  5. ^ "Native Win32 ports of some GNU utilities". unxutils.sourceforge.net.
  6. ^ IBM. "IBM System i Version 7.2 Programming Qshell" (PDF). IBM. Retrieved 2020-09-05.
  7. ^ Single Unix Specification#1980s: Motivation

Read other articles:

  لمعانٍ أخرى، طالع الرابح الأكبر (توضيح). يفتقر محتوى هذه المقالة إلى الاستشهاد بمصادر. فضلاً، ساهم في تطوير هذه المقالة من خلال إضافة مصادر موثوق بها. أي معلومات غير موثقة يمكن التشكيك بها وإزالتها. (فبراير 2016) الرابح الأكبر (الموسم الأول) النوع تلفزيون الواقع السلسلة ا

Editie uit 1909 Het Eiland der Pinguïns (Originele Franse titel: L'Île des Pingouins) is een satirische roman van Anatole France. Hij werd voor het eerst uitgebracht in 1908. Het boek bevat de geschiedenis van de pinguïns en is geschreven als een kritiek op de menselijke natuur. Daarnaast is het een satire op de Franse politieke geschiedenis, met inbegrip van de Dreyfus-affaire. Normen, waarden, omgangsvormen en wetten worden bespot binnen de context van het fictieve land Penguinia, waar d...

Car WarriorsPublication informationPublisherEpic ComicsScheduleMonthlyFormatLimited seriesGenre Post-apocalyptic Publication dateJune – September 1991No. of issues4Creative teamCreated bySteve JacksonSharleen LambardWritten byChuck DixonPenciller(s)Steve DillonInker(s)Phil WinsladeLetterer(s)Jade MoedeColorist(s)Steve BuccellatoJoe Rosas (issue 2)Editor(s)Marie JavinsMindy Newell (issues 3–4) Car Warriors is a four-issue comic book series published in 1991 by American imprint Epic Co...

SinPoster resmiSutradaraHerwin NoviantoGunawan Raharja (sutradara pendamping)Produser Frederica H.B. Naveen Dallas Sinaga (produser eksekutif) Ditulis oleh Johanna Wattimena Upi Avianto SkenarioJohanna WattimenaUpi Avianto (supervisi skenario)BerdasarkanSin: God hates the sin, not the sinnerkarya FaraditaPemeranBryan DomaniMawar de JonghPenata musikAndhika TriyadiSinematograferEdi Michael SantosoPenyuntingMuhamad Maulana Ali RidhoPerusahaanproduksiFalcon PicturesDistributorFalcon Pictur...

  لمعانٍ أخرى، طالع غراند رابيدز (توضيح). غراند رابيدز     الإحداثيات 47°14′14″N 93°31′49″W / 47.237222222222°N 93.530277777778°W / 47.237222222222; -93.530277777778  تاريخ التأسيس 1872  تقسيم إداري  البلد الولايات المتحدة[1][2]  التقسيم الأعلى مقاطعة إتاسكا  عاصمة لـ مق...

Fictional character Eric van der WoodsenGossip Girl characterConnor Paolo as Eric van der WoodsenFirst appearanceNovel: Gossip Girl Television: Pilot (episode 1.01)Last appearanceNovel: I Will Always Love You Television: New York, I Love You XOXO (episode 6.10)Created byCharacter: Cecily von Ziegesar Developed for television: Josh Schwartz Stephanie SavagePortrayed byConnor PaoloIn-universe informationFull nameEric van der WoodsenAliasE JOccupationNovels: College student (at Brown) Television...

Pelat nomor kendaraan pribadi (Bali) Pelat nomor adalah salah satu jenis identifikasi kendaraan bermotor. Pelat nomor juga disebut pelat registrasi kendaraan, atau di Amerika Serikat dikenal sebagai pelat izin (license plate). Bentuknya berupa potongan pelat logam atau plastik yang dipasang pada kendaraan bermotor sebagai identifikasi resmi. Biasanya pelat nomor jumlahnya sepasang, untuk dipasang di depan dan belakang kendaraan. Namun ada jurisdiksi tertentu atau jenis kendaraan tertentu yang...

Masjid Raya MakassarMasjid Raya MakassarAgamaAfiliasi agamaIslamLokasiLokasiMakassar, Sulawesi Selatan, IndonesiaKoordinat5°7′50″S 119°25′11″E / 5.13056°S 119.41972°E / -5.13056; 119.41972Koordinat: 5°7′50″S 119°25′11″E / 5.13056°S 119.41972°E / -5.13056; 119.41972ArsitekturJenisMasjidPeletakan batu pertama1948Rampung1949 Masjid Raya Makassar (Makassar: ᨆᨔᨗᨁᨗ ᨒᨚᨄᨚᨓ ᨆᨀᨔᨑ) merupakan sebuah masjid...

American baseball player (born 1966) Baseball player Dave LiddellLiddell in 1988CatcherBorn: (1966-06-15) June 15, 1966 (age 57)Los AngelesBatted: RightThrew: RightMLB debutJune 3, 1990, for the New York MetsLast MLB appearanceJune 3, 1990, for the New York MetsMLB statisticsBatting average1.000Home runs0Runs batted in0 Teams New York Mets (1990) David Alexander Liddell (born June 15, 1966) is a former Major League Baseball catcher. He caught one game for th...

Golf course in Japan Kasumigaseki Country ClubAn aerial photograph taken in 1989Club informationLocation of Kasumigaseki Country ClubCoordinates35°54′5″N 139°24′16″E / 35.90139°N 139.40444°E / 35.90139; 139.40444Location3398 Kasahata,Kawagoe, Saitama, JapanEstablished1929TypePrivateOwned byKasumigaseki Country ClubOperated byKasumigaseki Country ClubTotal holes18 x 2Websitekasumigasekicc.or.jpEast CourseDesigned byKinya Fujita, Shiro Akaboshi, and Charles H...

Legendary xian (immortals) in Chinese mythology For other uses, see Eight Immortals (disambiguation). Eight ImmortalsThe Eight Immortals (Walters Art Museum)Chinese八仙Literal meaningeight xianTranscriptionsStandard MandarinHanyu Pinyinbā xiānWade–GilesPa1-hsien1IPA[pá.ɕjɛ́n]Yue: CantoneseJyutpingbaat3 sin1Southern MinHokkien POJpat-sianMiddle ChineseMiddle Chinese/pˠat̚ siᴇn/Old ChineseZhengzhang/*preːd sen/ Part of a series onTaoism Outline History Concepts Daoxue Da...

Metro line in Osaka prefecture, Japan This article needs additional citations for verification. Please help improve this article by adding citations to reliable sources. Unsourced material may be challenged and removed.Find sources: Sakaisuji Line – news · newspapers · books · scholar · JSTOR (August 2014) (Learn how and when to remove this template message) Osaka Metro Sakaisuji LineA refurbished Sakaisuji Line 66 series EMU in January 2016OverviewNat...

Government building in Guatemala Republic of Guatemala National PalacePalacio Nacional de GuatemalaA view of the National Palace from the Parque Central in Guatemala CityGeneral informationArchitectural styleSpanish baroque and Spanish renaissancemLocationGuatemala City, GuatemalaConstruction started1939Completed1943InauguratedNovember 10, 1943 (1943-11-10)Renovated2010OwnerGuatemalan GovernmentDesign and constructionArchitect(s)Rafael Pérez de LeónEngineer Enrique Reyes Luis...

2009 film directed by Badri Ainthaam PadaiDirected byBadriWritten byBadri,Sakthi Krishna (dialogues)Produced byKhushbuStarringSundar CSimranMukeshVivekNassarCinematographyD. ShankarEdited byKasi ViswanathanMusic byD. ImmanProductioncompanyAvni CinemaxDistributed byAyngaran International MediaRelease date 23 July 2009 (2009-07-23) [1]Running time152 minutesCountryIndiaLanguageTamil Ainthaam Padai (transl. Fifth Creation or Fifth Army) is a 2009 Tamil language actio...

American stand-up comedian, radio personality, and podcaster For other people with the same name, see Bob Levy (disambiguation). Bob LevyLevy performing in 2012PseudonymThe ReverendBorn (1962-08-12) August 12, 1962 (age 61)Brooklyn, New York, U.S.MediumComedyTelevisionPodcastTalk radio NationalityAmericanGenresObservational comedyInsult comedySex comedyCringe comedyShock humour Subject(s)Modern societySexAmerican politicsChildren1Notable works and rolesThe Howard Stern ShowThe Killers of...

HuangobotuKelurahanNegara IndonesiaProvinsiGorontaloKotaGorontaloKecamatanDungingiKodepos96138Kode Kemendagri75.71.04.1001 Kode BPS7571011004 Luas... km²Jumlah penduduk2.291 jiwaKepadatan... jiwa/km² Huangobotu adalah salah satu kelurahan di wilayah kecamatan Dungingi, Kota Gorontalo, Provinsi Gorontalo, Indonesia. Pranala luar (Indonesia) Keputusan Menteri Dalam Negeri Nomor 050-145 Tahun 2022 tentang Pemberian dan Pemutakhiran Kode, Data Wilayah Administrasi Pemerintahan, dan Pulau t...

Франсиско де Сурбаран Геракл раздвигает горы Кальпе и Абила. 1634 холст, масло. 136 × 167 см Прадо, Мадрид (инв. P001241[1]) Геракл раздвигает горы Кальпе и Абила (исп. Hércules separa los montes Calpe y Abyla) — картина испанского живописца Франсиско де Сурбарана, написанная в 1634 г...

Isla Gran Roque Ubicación geográficaMar Mar CaribeCoordenadas 11°57′00″N 66°40′36″O / 11.95, -66.67666667Ubicación administrativaPaís Venezuela VenezuelaDivisión Dependencias FederalesEntidad Federal Dependencias FederalesCaracterísticas generalesSuperficie 1,8 km²Punto más alto (8 metros)PoblaciónPoblación 3100 (2014) hab.Gentilicio RoquenseOtros datosIntegración a las Dependencias Federales 20 de julio de 1938Administrador Gobierno del Territorio In...

1919 mayoral election in Invercargill, New Zealand 1919 Invercargill mayoral election ← 1917 30 April 1919 1921 → Turnout3,265 (38.52%)   Candidate John Stead T. D. Lennie Party Independent Independent Popular vote 1,673 1,559 Percentage 51.24 47.74 Mayor before election John Stead Elected Mayor John Stead The 1919 Invercargill mayoral election was held on 30 April 1919 as part of that year's local elections. Incumbent mayor John Stead was re-elected with a red...

Nowaki AuthorNatsume SōsekiOriginal title野分 (Nowaki)TranslatorWilliam RidgewayCountryJapanLanguageJapanesePublication date1907Published in English2011Media typePrint (Paperback)ISBN978-1-929280-68-1 Nowaki (野分 Nowaki) is a short Japanese novel by Natsume Sōseki (1867–1916). Written in 1907, the novel was published in the magazine Hototogisu in January. The year 1907 was a turning point in the author's life when he left his Tokyo University teaching position to write...

Kembali kehalaman sebelumnya