LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Blogs > Skaperen
User Name
Password

Notices


Rate this Entry

A feature i have never liked

Posted 03-09-2021 at 06:07 AM by Skaperen

there is a feature in Linux i have never liked. it's in other Unix/POSIX system's, too, so it's not Linux specific. as far as i recall, it predated Linux. the feature in the "mv" command. if you name a directory as the target of a move, it puts the file (or whatever is being moved) inside that directory. if the target is not a directory, obviously it can't, and that's not my issue with the "mv" command. if there is nothing at the target name, "mv" just move the file being moved to become the target (if a parent directory exists).

i wrote a new command i now use on me own laptop. i'm testing it out to see what issues it might have in practical use. it is named "mvd". it specifically ensures that the target exists and is a real directory.

i wrote this command in the Python language. Python has been around for decades and all the major desktop and server distribution have it. i have also made a function (for Python coding) named "mvdir" that creates the directory and needed parents if it is missing. Python coders already have a safe way to just rename a file without unexpectedly putting it inside a directory (the os.rename() method). my function also has an option to disable creating parent directories.
Posted in Uncategorized
Views 166 Comments 2
« Prev     Main     Next »
Total Comments 2

Comments

  1. Old Comment
    I totally understand where you're coming from.

    I've always wanted mv to be separated into two commands: move (to move file or a directory someplace) and rename (to rename file in-place). Having them both in the same command has always made me (in a conceptual sense) trip and stumble when doing file management. You can actually use mv (as it is now) to (accidently or not) delete things! D'oh!

    That said, important low-level system commands should be in .c.
    Posted 03-11-2021 at 07:11 AM by jr_bob_dobbs jr_bob_dobbs is offline
  2. Old Comment
    the move/rename separation seems like a reasonable approach. i like that naming concept.

    one thing that has always bothered me is that many commands force you to have existing directories for new file paths, instead of creating parent directories as needed. Python does have a function named "renames" (in the "os" module) that creates directories as needed for where a file is going to. it also removes directories that are no longer needed (now empty) from where a file is taken from. not all file system actions are covered by this.

    as for being in C, i don't see a need. i code in both C and Python and see the latter as quite capable in most cases, if not all. the only place i see a need for C is where the Python interpreter can't be, such as small embedded systems and early stage boot straps. i'd be doing even more in Python if it had more kernel syscall interfaces (the stubs get implemented in C).
    Posted 03-11-2021 at 02:06 PM by Skaperen Skaperen is offline
 

  



All times are GMT -5. The time now is 12:07 PM.

Main Menu
Advertisement
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration