Tag Info

New answers tagged

0

Usually the extension should be .sh, but that's a bit cumbersome in this case. Just put the script, for instance, $HOME/bin and export PATH=$HOME/bin:$PATH in $HOME/.bashrc. Now you can . mypyenv from anywhere. (The . is the historical version of the source command.) For a more general solution to this problem, see the modules package. ...


1

Extension doesn't really matter, but I'd name it .sh since this is shell commands, not a set of option: value. But be careful that if you don't include those lines in your .bashrc, you will need to source it anytime you need these variables in a new terminal. $ echo $PYTHONPATH $ source /pat/to/my_conf.sh $ echo $PYTHONPATH /home/myuser/squish-5.0-xyz/lib ...


1

To remove a trailing slash if there is one, you can use the suffix removal parameter expansion construct present in all POSIX-style shells: x=${x%/} There are a few complications. This only removes a single slash, so if you started with a/b/c// then you'll still end up with a slash. Furthermore, if the original path was /, you need to keep the slash. ...


1

Background reading: Why does my shell script choke on whitespace or other special characters?, Why you shouldn't parse the output of ls Setting IFS to a newline means that only newlines, and not spaces and tabs, will be treated as separators during the expansion of the command substitution. Your method will not support file names that contain newlines; this ...


1

Do you really mean adding * in filename? Or you mean the output of ls gives filename ending in * if it has execute permission? If only output problem of ls, you could simply solve by: replace ls to \ls, this is to use un-aliased version of ls, which doesn't output *


2

For various reasons related to whitespace issues, etc., it is not advisable to parse the output of ls. An alternative, which uses GNU versions of find, sort, sed: find . -mindepth 1 -maxdepth 1 -printf "%A@ %f\0" | sort -rnz | sed -z 's/^[0-9.]\+ //' find is, of course, much more flexible than ls when it comes to listing and filtering files, but it ...


4

dir=${1%/} will take the script's first parameter and remove a trailing slash if there is one.


0

You can use something like this: ls -1Atu | while IFS= read -r entry; do echo "$entry" done With this example, the output is generated once, and the while read entry section causes the output from ls to be parsed line-by-line, which solves the issue with your for example where everything was getting placed in $i in a single round.


0

I don't think there are any builtin or bash-completion standard function to complete only bare filenames. Directories can contain files so the standard behaviour for completing a filename is to complete on files and directories (as bash-completion's _filedir does. It has an option for only directories, but not for only files.). You could write a custom ...


11

A case-insensitive filesystem just means that whenever the filesystem has to ask "does A refer to the same file/directory as B?" it compares the names of files/directories ignoring differences in upper/lowercase (exactly what upper/lowercase differences count depends on the filesystem—it's non-obvious once you get beyond ASCII). A case-sensitive filesystem ...


0

It doesn't seem that detox has an option for that. It should be fairly simple to modify the source code to add a filter with your desired output (a small modification of the safe filter; don't forget to ensure that any leading - gets removed). You could postprocess the result of detox, or use other tools altogether. There are many file renaming tools that ...


-1

I want to compare the filenames from two different directory by neglecting extenstion. in 1directory1 file2.csv file2.done and /directory2 has files like file.csv.completed file2.csv.completed. based on the /dir2 files I need to move the /dir1 files.


0

You are close. Step-by-step, here's how to delete the file by inode number. First, find the inode number of the file you want, using ls -li. The inode number will be in the first column of output. For example: $ls -li 311010 -rw-rw-r-- 1 me me 3995 Apr 6 16:27 -???\# ;-) In this case, the inode number is 311010 Use find to look for the file by inode ...


14

heemayl is correct about the location of crontab files on Linux, but it might be different on other operating systems and "theoretically" is could also be in a different location on Linux. Essentially, when a special interface is provided to access the files, you should use it. This will ensure that cron gets to check the files before installing them, makes ...


5

The location of cron files for individual users is /var/spool/cron/crontabs/. From man crontab : Each user can have their own crontab, and though these are files in /var/spool/cron/crontabs, they are not intended to be edited directly.


24

That's a really nice catch. From a quick look at the source code for GNU find, I would say this boils down to how fnmatch behaves on invalid byte sequences (pred_name_common in pred.c): b = fnmatch (str, base, flags) == 0; (...) return b; This code tests the return value of fnmatch for equality with 0, but does not check for errors; this results in any ...


13

find -name option uses shell pattern matching notation to perform matching filename. * is a pattern matching multiple characters, shall match a string of zero or more characters. find uses fnmatch to check pattern matching, so you can use ltrace to check the result: $ touch $'\U1212'aa $ touch D$'\351'sinstaller $ LC_ALL=en_US.utf8 ltrace -e fnmatch find ...


0

Because if you were able to do such a thing, life would be miserable for programmers like me when I try to iterate files in a directory. For the following pseudocode: isDir('/path/to/same_file_and_folder_name') Should the OS reply true or false?



Top 50 recent answers are included