Tag Info

New answers tagged

0

In virtual box, login to Ubuntu. In menu bar click devices -> USB devices -> Select your device (Pendrive). Then go to the Home folder. On the left you'll see your device.


1

To do a single file: $ avconv -i m.m4a m.mp3 To do a batch you could wrap this in a for loop: $ for i in *.m4a; do avconv -i "$i" "${i/.m4a/.mp3}" done This will take all the files that are present in the current directory with the extension .m4a and run each of them through avconv. The 2nd argument, ${i/.m4a/.mp3} does a substitution on the ...


4

cat * myfile.log is going concatenate all the files in the directory (and "myfile.log" twice since it's included in the * and you named it) and print them to the screen (standard output). cat * >> bigfile is going to concatenate all the files in the directory (* = everything) and append them to a file named "bigfile" (or write them to that file if it ...


2

Fakeroot The fakeroot utility, or the newer utility fakeroot-ng (same purpose, different implementation technique) runs a program and pretends to the program that it is running as root and that system calls such as chown succeeded. Only the program believes that these calls succeeded, nothing is actually reflected in the filesystem (it can't be since ...


3

The kernel knows which pages are modified the same way it does any other page: when its written to, a flag in the page tables is set to mark it "dirty". That's done either by the CPU or MMU, or with their help (e.g., they may set the bit directly, or raise an interrupt to have software do it). But actually, the behavior you're assuming isn't guaranteed. ...


3

How can I create a tar.xz archive, so that the files have root ownership when unpacked by root? That's up to the root who unpacks: tar --no-same-owner -xf ... If you want to make them all root to start with, you can use tar --owner=root --group=root -cf ...


0

It looks like Linux Mint 15 Olivia uses the aufs and/or unionfs filesystems. I've not used Linux Mint but Puppy Linux uses aufs and the behavior you describe is indicative of a multi-layered filesystem like aufs. The short answer is that when you delete files that are part of the original distribution, they are not actually deleted, but they do disappear ...


1

One of the approaches is: while read -r line; do rm -rf "${line%%/*}"; done < <(find . -type f -mtime +180 -printf "%P\n") Pipe the into read and execute a command accordingly.


5

With GNU tools: for d in Dir*; do find "$d" -mindepth 1 -mtime -180 -print -quit | grep -q . || echo rm -rf "$d" done Remove the echo when satisfied. Remove the -q to find out why a directory is not being removed.


0

It looks to me like both files are already sorted on the first field. If so: join file1 file2 is best, by about as far as your files are large.


1

You can use awk: $ awk 'FNR==NR{a[$1];next}($1 in a){print}' file2 file1 A0001 C001 A0024 C234 B1542 C231


4

This should do the job: grep -Ff File2 File1 The -f File2 reads the patterns from File2 and the -F treats the patterns as fixed strings (ie no regexes used).


3

Looking at the man page for this there does seem to be any way to avoid passing the text as an argument - there appears to be no way to pipe the data in or have dialog read directly from the file. However, you could limit the size of the argument using head. On most Linux systems the maximum size for a single argument is 32KiB, so you could do: dialog ...


7

s=/home/poney/; f=folderfulloffiles; d=/home/unicorn/ sudo mv $s$f $d && sudo chown -R unicorn:unicorn $d$f About the same length as the other answers, and note since they're all using the same library calls under the hood, they're all doing exactly the same thing -- unless, as Gilles notes, this is on the same filesystem and device, in which case ...


9

Per @Kevin in the comments below, the --file - |pipe syntax is redundant. So I've removed it. This can also be done with tar: sudo tar -C${SRC_DIR} --remove-files --group=unicorn --owner=unicorn -c ./* | sudo tar -C${TGT_DIR} -pvx


20

Use rsync(1): rsync \ --remove-source-files \ --chown=unicorn:unicorn \ /home/poney/folderfulloffiles /home/unicorn/


2

Depends on the flavor of Unix you're using, I guess. In OS X, you can use the open command: OPEN(1) BSD General Commands Manual OPEN(1) NAME open -- open files and directories SYNOPSIS open [-e] [-t] [-f] [-F] [-W] [-R] [-n] [-g] [-h] [-b bundle_identifier] [-a application] file ... [--args arg1 ...] ...


4

If you mostly work on the command line, you could look at a curses-based file manager, like ranger or vifm. Both allow you to define default actions for filetypes. In vifm, for example, in ~/.vifm/vifmrc you can define associations like so: " Images filetype *.jpg,*.jpeg,*.gif,*.tif,*.png,*.bmp sxiv " Media filetype ...


4

Sort of, but it will change your default application as a result. I'm not sure what other operating systems this works on, but the instructions below work for Ubuntu 12.04 - Desktop X86-64. I didn't have any pdf files handy so I tested with a .zip archive. General Steps Step #1 In a terminal type: $ mimeopen -d /home/username/example.zip screenshot #1 ...


24

There isn't a command that I've ever seen that will act as "open with..." but you can use the command xdg-open <file> to open a given <file> in the application that's associated with that particular type of file. Examples Opening a text file: $ xdg-open tstfile.txt $ Resulting in the file tstfile.txt being opened in gedit: ...


1

The problem is that the shell redirection (<) sends the file over the ssh tunnel. And the Java class is expecting not the file, but a string with the "filename" of a local file that will be read with a FileReader. Instead of passing the filename to the FileReader, read from the standard input. InputStreamReader isReader = new ...


-1

The local file, by definition, is on your local machine. The java program is on a remote machine. The remote machine does not know about your local file, and in any production situation probably does not have permission to read it. I can think of three general approaches to this situation: 1) Change your Java program to read from stdin instead of from a ...


3

I don't know anything about Java, but I can show you a proof of concept. Say we have localfile.txt: Here is the local file. and on the remote machine, we have remote.sh: #!/bin/bash cat /dev/stdin Note that the script on the remote machine invokes a program which reads from stdin. Then pass the contents of localfile.txt to your ssh command: ...


1

The methods you've mentioned are how I would've attempted to do it, in particular ACLs using setfacl to do it. I'd try and set the ACL at the top and make it so that it's recursively applied, but this would not protect files/dirs that are moved into this directory which are lacking it, I believe. You could use something like incron to run a script anytime ...


6

Most basic shell tools are not designed for any very specific purpose at all. Most basic shell tools are designed only to interact with others to achieve your purpose. Or maybe it should be said that most tools do only one very basic thing regardless of how they might be combined to achieve a goal. : >./file That creates an empty file. Or truncates an ...


4

Sometimes, when you start a program, it prints out some message. If you start it in background, the program may lock up until you bring it back to the foreground so that it can display its message. The solution is to redirect stdout and stderr so that the program can continue running in the background. One way to do this is: evince myfile.pdf ...


5

evince myfile.pdf CTRL+Z bg That opens the program, suspends it, then backgrounds it. Or: ( evince myfile.pdf ) & Would open evince in a (subshell) and backgrounds the (subshell). It's a little weird that simply: evince myfile.pdf & doesn't work though because it does for me. You might want to: echo $- And check your job control ...


9

Adrian Frühwirth's answer is right on. I just wanted to add that there is actually a command specifically written to create files: mktemp. NAME mktemp - create a temporary file or directory SYNOPSIS mktemp [OPTION]... [TEMPLATE] DESCRIPTION Create a temporary file or directory, safely, and print its name. TEM‐ PLATE must ...


28

I would say because it's hardly ever necessary to create an empty file that you won't fill with content immediately on the command line or in shell scripting. There is absolutely no benefit in creating a file first and then using I/O redirection to write to the file if you can do so in one step. In those cases where you really want to create an empty file ...


0

I suggest you the following bash script : #!/bin/bash FIRST=1 unset TARFILE unset FILESET find . -name '????_??_??_*.txt' | sort | while read fn do CURTARFILE=`echo $(basename $fn)|awk -F_ '{print $1"_"$2"_"$3".tar.gz"}'` if [ "$CURTARFILE" == "$TARFILE"] ; then FILESET=$FILESET" \"$fn\"" FIRST=0 continue fi [ ...


2

This is very simple: tar -cvzf 2014_04_01.tar.gz 2014_04_01_??.txt Update To do this for multiple dates (GNU find): find . -maxdepth 1 -name '????_??_??_??.txt' | cut -d_ -f 1-3 | sort -u | while read date; do tar -cvzf "$date".tar.gz "$date"_??.txt done


3

The following should work provided you don't have any underscores in the last part of any of the filenames (and nothing else in the directory that matches the glob): for file in ????_??_??_*.txt; do echo cat "$file" ">>""${file%_*}.txt" done Remove the echo part and the quotes around the >> when you are sure you have what you want.


3

^@ is a representation of the null byte. You can get a better picture from xxd or od. If the contents of the file has been lost, the fix would be to restore it from the version control system or backups.


0

It looks like your list is sorted by size, or could easily be sorted by size, so if you wanted to optimise this a bit using First Fit Decreasing strategy, you could use the following Awk script (lovely, and understandable) with tac to read the input file from the bottom (only required because it's sorted by file size in ascending order): BEGIN { ...


2

You can call lsof to list the open files of the shell process. Use -a -p $$ to limit the output to the shell process ($$), -d 1 to limit the output to file descriptor 1 (for instance), and -F n to print the output in parseable form. Here's a shell snippet that copes with arbitrary characters in file names: output_file=$(lsof -a -p $$ -d 1 -F pn; echo .) ...


2

In this scenario, the only guarantee you have is that B will either not copy the file, or copy a prefix of the file. B has no way to know that the file is being written to, so it will read to the (current) end of the file, then stop. The common way to avoid this pitfall is to copy the file under a temporary name, then rename it afterwards: ...


2

df -i / gives you the number of used inodes on the root filesystem (on filesystems that use inodes, which includes the ext2/ext3/ext4 family but not btrfs). This is the number of files on that filesystem, plus a few inodes that are preallocated for the use of fsck. If you want the number of files in a directory tree, then you can use the following command: ...


2

UPDATE This is the fastest method I can imagine that this can be done fully portably. I use tar below because it will automatically add hard linked files only once: find /./ -xdev ! -type d | tar -cf - - | tar -t | sed -n '\|^/\./|c.' | wc -l portable and very fast: find / -xdev | sed -n '/^[./]/c\.' | wc -l I don't believe you do need all of the ...


4

Depending on what exactly you want to count, you are better doing this per filesystem rather than counting all files under root. Counting everything under root would also count /proc and /sys files which you may not want to include. To count everything on the root filesystem using GNU find, you could do: find / -xdev -type f -printf '\n' | wc -l The ...


1

I think the best thing to is to ensure that process B only copies files which have been fully transferred by process A. One way to do this would be to use a combination of cp and mv in process A, since the mv process uses the rename system call (provided the files are on the same filesystem) which is atomic. This means that from the perspective of process B, ...


0

From your root directory: find . -type f | wc -l You can change the path (here .) to whatever the directory you want to count the files in. If you don't want to go in subdirectories, add the option -maxdepth 1


0

The output.log and error.log files are created in the current directory i.e. the $PWD variable value. If you want your program to use these files later, just save their directory in a variable before running your script. Here is an example : OUTDIR=$PWD ./script.sh 1> output.log 2> error.log # Whatever you want to do else ... echo The output file : ...


4

{ readlink /dev/fd/[1,2] ; echo "out" ; } >./file 2>./error { readlink /dev/fd/0 ; cat ; } <./file OUTPUT: /home/mikeserv/file /home/mikeserv/file /home/mikeserv/error out { readlink /proc/$$/fd/[1,2] ; echo out ; } >./file 2>./error { readlink /proc/$$/fd/0 ; cat ; } <./file OUTPUT: /home/mikeserv/file /home/mikeserv/file ...


0

In your case, STDOUT will be saved to file output.log and STDERR will be saved to file error.log. Both files are saved in the same directory with script.sh. If you want your program "know the path to these files", you must use absolute path: ./script.sh > /path/to/output.log 2> /path/to/error.log


1

Since you want a serial console, I suppose your using some embedded device. So I guess the partition /etc/inittab is on is mounted read only. You'd have to remount the partition writable. Use mount without arguments to figure out what partition the file is on and use something like mount -o remount,rw /etc/ to remount it writable.


1

Try this: Open terminal, then type su and type your root user password. After this: vi /etc/inittab In my case this works but I'm using CentOS.


15

You can use the command archivemount to mount archives such as .tar.gz. $ ls files.tgz mnt/ $ archivemount files.tgz mnt $ ls mnt file1 file2 [... Perform desired read/write operations on the archive via mnt/ ...] $ umount mnt [... Any changes are saved to the archive ...] See the man page for archivemount for more info. It's often times not ...


6

You're either talking about a FUSE filesystem (filesystem in userspace - Linus calls them toys) or a custom compiled kernel OR squashfs. Squash is not exactly as you describe - you cannot simply mount a tarball for instance - not with the kernel supported VFS, anyway - but you can certainly mksquash any number of files or directories and mount the resulting ...


0

Mount the zip archive as a filesystem with fuse-zip. Then you can access files in it using any command you like. mkdir foo fuse-zip foo.zip foo Then, to copy needle.txt from whichever subdirectory it's in: find foo -name needle.txt -exec cp -p {} . \; Or using the shell's recursive globbing (in bash, you need to run shopt -s globstar first; in zsh this ...


0

Why not use something like KDirStat Although it was originally written for KDE but it works fine with GNOME aswell It gives you best view of number of file/dir and respective usage in GUI



Top 50 recent answers are included