Stack Exchange Network

Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

New answers tagged

0

sed 's/a0.*ppid/ppid/g' yourFile s means to substitute It replaces string starting with a0 and ending with ppid with ppid The period means any character The asterisk means 0 or more of any character up until ppid g means do it for the whole string Type man sed in a terminal to learn more


0

I figured out what went wrong: The command takes quite some time to finish. In the console the output is immediately shown to the screen. Therefore I expected the file also to be immediately filled with some (intermediate) output. However, only when the command fully completed the file was filled with the correct output.


0

Yes, you can control the cursor in bash when reading a file, but in order to do that, you need to use a single file redirect operation (<), which would be equivalent to an open() or similar in C/C++. Here is code in bash that is mostly equivalent to the C++ code you mentioned: do_something () { local linenumber linenumber=$1 shift echo "doing ...


8

As all current file systems do not require the file to be stored in a continuous memory block, Filesystems might not require files to be stored in a continuous area (and that would be very inflexible indeed), but usually files are stored in fixed-size blocks (or sequences of contiguous blocks). Doing it that way simplifies the implementation, and the blocks ...


21

On recent Linux systems that is actually possible, but with block (4096 most of the time), not byte granularity, and only on some filesystems (ext4 and xfs). Quoting from the fallocate(2) manpage: int fallocate(int fd, int mode, off_t offset, off_t len); [...] Collapsing file space Specifying the FALLOC_FL_COLLAPSE_RANGE flag (available ...


1

You can use sw_vers to determine this: $ sw_vers ProductName: Mac OS X ProductVersion: 10.14.5 BuildVersion: 18F132 Or, for a more succinct answer: $ sw_vers | awk '$1 ~ /ProductVersion/ { print $2 }' 10.14.5


5

touch -- change file access and modification times touch(1) Note: while you could do touch * this won't recurse into subdirectories and will create a file named * if no files exist. A more robust solution would be to use: find /path/to/root_dir/ -exec touch -a {} \; Additionally it seems like you only want to update the modify time of the directories? ...


1

curl has --range/-r switch, which is documented to support both HTTP and FTP (and even SFTP) protocols: curl --range start-end ftp://example.com/file.ext --output test.ext


0

To delete the "last" (highest-numbered "run") log file for each set of jobs and dates, I would suggest a ksh93-based solution that can keep track of the highest job runs seen for each combination as well as a list of files to delete: #!/bin/ksh93 typeset -A highestjobruns=() typeset -A deletions=() for logfile in *_????????_*.log do base=${logfile%.log} ...


0

If you boot with a LiveUSB (Windows instructions also available) you can use gparted to expand a partition IF you don't end up moving the boot partition start point. If you need further assistance, run fdisk, copy the screen contents, then go to your original question and click on edit to paste the results into your question so we can see more about your ...


0

find . -maxdepth 1 -size +10M -exec du -shk {} \;| sed "s/\.\///g"|awk '$1 > 50 {print "split -l Specifylinenumber" " " $2}'|sh After above file whose size is greater than 10M will be splitted as xaa,xab,xac and so on Use below command to get it renamed f=1;for i in xa*; do mv $i debug.log.00$f; f=$(($f+1)); done


1

You can choose the file-ending for the split files with the option --additional-suffix make | tee >(split --additional-suffix=.log -d -b 10000000 - debug.0)


2

If you own the file then you can pretty much do anything with it and filesystem permissions won't stop you. Permissions such as "000" aren't designed to protect you from yourself, it's to protect files from other people using the same system. So if you have one person who logs in as 'user1' and another who logs in as 'user2' then filesystem permissions can ...


3

With zsh: printf '%s\n' *([5]) Gives you the 5th non-hidden file in lexical order. Change to *(D[5]) to include hidden files (note that . and .. are never included). In any Bourne-like shell, you can do the same with: set -- * printf '%s\n' "$5"


-2

This work in any shell: ls | awk "NR==$fileIndex{ print; }" Explanation: ls returns all the files in a directory in alphabetical order, and piping ls runs each file on its own newline, and awk "NR==$fileIndex{ print; }" will print the line number defined by $fileIndex.


0

For simple filenames such as these, where you can guarantee that they will not contain strange characters such as newline, it is safe and convenient to parse the output of ls. (In the general case this is not recommended.) As described in your question let's assume we're working with files matching these pattern, where the * will of course match "anything": ...


3

$ tree . |-- dir1 | |-- file1 | |-- file2 | |-- file3 | |-- file4 | `-- file5 `-- dir2 |-- file2 |-- file4 `-- file5 2 directories, 8 files $ for f1 in dir1/*; do f2="dir2/${f1#dir1/}"; [ ! -e "$f2" ] && printf '%s\n' "$f2"; done dir2/file1 dir2/file3 This loops through all the names in the first directory, and for each ...


3

Try this: #!/bin/bash while read file; do stat -c '%A %n' "$file" >> $(stat -c '%a' "$file").txt done < <(find "$1") Usage: ./script.sh /path/to/directory the first stat -c '%A %n' "$file" prints the permissions and path to the file, e.g. -rw-rw-rw- /foo/bar the second stat -c '%a' "$file" prints the permissions in octal form, e.g. ...


1

Looks like you will have to virtualize Windows, and in Windows, run Digital Voice Editor (Open Source), Brorsoft Converter, Wondershare Uniconverter, or that Sony app you found.


0

It's possible, but it's not easy. you need to be a programmer. That's the GTK-3 file dialogue modifying the right parts of libgtk would change it libgtk is written in an object-oriented style in the language C. sudo apt-get build-dep libgtk-3-0 apt-get source libgtk-3-0 Will get you everything but the skills and knowledge needed to modify it. gtk docs ...


0

Using bash: shopt -s globstar dos2unix ** The globstar shell option in bash enables the use of the ** glob. This works just like * but matches across / in pathnames (hence matching names in subdirectories too). This would work in a directory containing a moderate number of files in its subdirectories (not many thousands). In the zsh and yash shells (...


1

There's no convenient way. That's why GNU find added -readable and friends. You can build an expression that approximates the permission test by enumerating the groups that the user is in. Untested. can_access="( -user $(id -u) -perm -0${oct}00 -o (" for g in $(id -G); do can_access="$can_access -group $g -o" done can_access="${can_access% -o} ) -perm -...


0

The zsh shell has special wildcard expansion features that would help. list files older than 30 days in the current directory: ls -d -- *(.m+30) remove files older than 30 days in the current directory: rm -- *(.m+30) The zsh syntax of *(.m+30) is a wildcard that means: * -- any filename ( ... ) -- with a qualifier of... . -- a regular file (not a ...


2

To list the files before you delete them: find . -maxdepth 1 -mtime +30 -type f -ls To delete the files: find . -maxdepth 1 -mtime +30 -type f -exec rm {} + with . specifying the current directory -maxdepth 1 descend at most 1 level of directories -mtime +30 only files last modified > 30 days -type f only regular files


0

Let's lay down some assumptions: Your shell is bash Your Directory A is dirA Your Directory B is dirB Your Directory C does not exist yet, but will be named dirC All the files you care about exist in dirA or dirB or are possibly duplicated in those directories The simplest way I can think of is to: rm -rf dirC; mkdir dirC cp -p dirB/*.dm4 dirC/ cp -p dirA/...


0

Copy all files of dirA to dirC cp dirA/*.dm4 dirC Then copy all files from dirB, skipping exising files in dirC cp -n dirB/*.dm4 dirC/ Man Page for cp: -n, --no-clobber do not overwrite an existing file (overrides a previous -i option) Note: -n checks for file names only, to check for versions, the-update option might be ...


0

A slow but relatively memory-friendly version, using ruby. About a dozen MB of RAM, regardless of input size. # count.rb ARGF. each_char. each_with_object({}) {|e,a| a[e] ||= 0; a[e] += 1}. each {|i| puts i.join("\t")} ruby count.rb < input.txt t 20721 d 20628 S 20844 k 20930 h 20783 ... etc


4

The values are shown using powers of 2, not powers of 10; so 1M is 1,048,576 bytes, and 1G is 1,073,741,824 bytes. If you divide accordingly, the values match the ls output (rounded up): $ echo $((84972633333.0/1024/1024)) 81036.218007087708 $ echo $((84972633333.0/1024/1024/1024)) 79.136931647546589 You can specify KB, MB, GB etc. instead to use powers ...


1

I was looking for an answer in C, and this question from several years ago shows up as a first Google result, though it focuses on shell scripts, I think I will share my findings for anyone else who is looking. As mentioned around this and related questions, there is no portable way. Here are some non-portable ways in C to get filesystem type based on a ...


0

find . -type f -name "*.mp4" -execdir bash -c ' [[ -f folder.jpg ]] && mv -v folder.jpg "$(basename {} .mp4).jpg"' \;


7

Try: for movie in ./*/*.mp4; do mv -- "${movie%/*}/folder.jpg" "${movie%.mp4}.jpg"; done ${movie%/*} and ${movie%.mp4} are both examples of suffix removal. ${movie%/*} returns the directory that the movie file is in and ${movie%.mp4} returns the name of the movie file minus the extension .mp4. Example Consider three directories, dir1, dir2, and dir3, ...


1

It is technically limited to maximum value of unsigned long (C Lang) i.e. 4,294,967,295 Reference : fs.h file /* And dynamically-tunable limits and defaults: */ struct files_stat_struct { unsigned long nr_files; /* read only */ unsigned long nr_free_files; /* read only */ unsigned long max_files; /* tunable THIS IS OUR VALUE */ };


3

names=( "$dir"/[!_]* ) if [ -e "${names[0]}" ]; then echo 'there are filenames that do not start with underscore' printf '%d of them\n' "${#names[@]}" fi Or, for /bin/sh (and bash for that matter): set -- "$dir"/[!_]* if [ -e "$1" ]; then echo 'there are filenames that do not start with underscore' printf '%d of them\n' "$#" fi In short, ...


3

You could accomplish this with a single redirection using echo/printf along with command substitution: printf '%s\n' "$(whoami)" "$(date)" > /home/user/folder/file IMO this is not a good solution, it is not very readable/manageable...especially if more commands are added. In order to prevent having to type the path multiple times you could just save it ...


5

Use a subshell (whoami; date) > ~user/directory/file


0

I tried using a CIFS mount instead of NFS and this solved the problem! Linux doesn't like to talk to Windows via the NFS mount.


3

Run sudo chmod o-t /var/host/media. Reference: https://sysctl-explorer.net/fs/protected_symlinks/ This is the problem with your permissions: drwxrwxrwt. 5 root root 100 May 20 21:22 media The t at the end of this means that the directory is sticky. Quoting from the linked webpage: When set to "1" symlinks are permitted to be followed only when ...


0

Try to use visudo instead of vi sudo visudo


1

sudo apt-get install ntfs-3g fixed it


0

Considering you have over-written your Ubuntu partition with a Windows reinstallation, chances of recovering files are pretty low. With : A LOT of time a pretty large storage space on another drive another PC where you can plug your hard drive (stop writing on your Windows/Ubuntu drive NOW!!!) an indecent amount of luck (sorry) you may recover some files ...


0

Whether or not there is a specific problem with /sys/power/wakeup_count, the answer is that files in the /sys filesystem are special virtual files. Reading and writing them provides access to kernel features. It is possible that some files under /sys or other virtual filesystem will block on reads, until a specific event happens. Exclude /sys and /proc. ...


0

date0='20190501' date1='20190622' numDays=$(( ( $(date -d "$date1" +'%s' ) - $(date -d "$date0" +'%s' ) ) / (60*60*24) )) for day in $( seq 0 $((numDays-1)) ); do d=$(date -d "$date0 + ${day}days" +"%Y-%m-%d") echo $d $( find . -maxdepth 1 -type f -newermt "$d" ! -newermt "$d + 1day" | grep '.' -c ) done Get number of days by difference between date0 ...


0

I'd like to direct anyone who's still being linked to this answer to the excellent answer Guiles Quernot gave to this question which doesn't require find. The resulting command would be: shopt -s globstar rename -n 'y/a-z/A-Z/' ** But before running please read the answer linked for caveats regarding old bash versions. Finally in case someone is ...


0

Try this code: TIME_STAMP=(`find . -maxdepth 1 -type f -printf '%TY-%Tm-%Td\n' | sort | sed -e 1b -e '$!d'`) LIST () { date1=$1 date2=`date -d "$date1 + 1 day" +"%Y-%m-%d"` find . -maxdepth 1 -type f -newermt $date1 ! -newermt $date2 | echo "$date1 `wc -l` " [ $date1 == $2 ] && exit 0; LIST $date2 $2 } LIST ${...


0

In order to recover a file, please use extundelete tool from link http://extundelete.sourceforge.net/


Top 50 recent answers are included