I have question about some command in linux - linux

I've learned linux and there's my homework:
Show all files and directories in /usr and save the result in file usr.txt:
Show all files in /usr/bin and stop when the screen is full:
Hint: use command pipe and more
Find all files in /etc that the file name contains the word “log”:
Hint: use command grep
1.I searched copy command on google but there's just some commands about copy file not contents and I also use Y1G command but there're nothing happen.
2.I absolutely don't have any idea about how to pharse "the screen is full" by commands
3.I've use command find path -log /etc but there're no right result

Show all files and directories in /usr and save the result in file usr.txt:
cd /usr && ls -l > usr.txt
Show all files in /usr/bin and stop when the screen is full:
Hint: use command pipe and more
ls -l /usr/bin | more
Find all files in /etc that the file name contains the word “log”:
grep -ir "log*" /etc

Related

How to list down all the soft links only inside a directory in Linux systems

What is a shortcut command to list all the links inside a directory in linux machines. I can list all files and folders and copy output in a temp file and from there I can do a grep, but what I am looking for is a shortcut command to do the same.
and copy output in a temp file
This is exactly the situation for pipes!
ls -la | grep "^l"
The stdout of ls -la is redirected to the input of grep. It sounds like you know, but just for completeness the "^l" is a regular expression that searches for an l at the start of a line.
1.Open a terminal and move to that directory.
2.Type the command: ls -la. This shall long list all the files in the directory ` even if they are hidden.
3.The files that start with l are your symbolic link files.

shell script mv is throwing unhelpful error "No such file or directory" even though i see it

I need to use a shell script to move all files in a directory into another directory. I manually did this without a problem and now scripting it is giving me an error on the mv command.
Inside the directory I want to move files out of are 2 directories, php and php.tmp. The error I get is cd: /path/to/working/directory/php: No such file or directory. I'm confused because it is there to begin with and listed when I ls the working directory.
The error I get is here:
ls $PWD #ensure the files are there
mv $PWD/* /company/home/directory
ls /company/home/directory #ensure the files are moved
When I use ls $PWD I see the directories I want to move but the error afterward says it doesn't exist. Then when I ssh to the machine this is running on I see the files were moved correctly.
If it matters the directory I am moving files from is owned by a different user but the shell is executing as root.
I don't understand why I would get this error so, any help would be great.
Add a / after the path to specify you want to move the file, not rename the directory.
You should try this:
mv $PWD/\* /home/user/directory/
Are your variables properly quoted? You could try :
ls "$PWD" #ensure the files are there
mv "$PWD"/* "/company/home/directory"
ls "/company/home/directory" #ensure the files are moved
If any of your file or directory names contains characters such as spaces or tabs, your "mv" command may not be seeing the argument list you think it is seeing.

Find out which scripts create files in the /tmp folder on linux

Is it possible to trace which files are creating files in the /tmp folder on a linux OS? I want to back trace some files to find out where they have come from
If the files are open you could find the processes with something like
ll -d /proc/[1-9]*/fd/* | grep /tmp/

Generate file that contains a list of all files in a directory on linux

I know how to do this on windows, but I want to create a list of files that are in a directory on a linux machine, either as a txt or csv file. Or is there a way to save the output of a command rather than showing it on screen? Any help is appreciated.
ls lists the files in a folder, check man ls for options. To save the output of a shell command use redirection, e.g.:
ls > list.txt
or
ls -l > list.txt
etc.

Only get folders using smbclient

I'm struggling to only retrieve subfolders from a remote windows share with the following directory structure using smbclient. Is there a way of issuing a command to only get folders? The command I have so far is:
smbclient //$host/$share -U"$USER%$PASSWORD" -c 'cd RootFolder; prompt; recurse; mget Test*\'
RootFolder/
Test001/
Revisions.txt
Test002/
Revisions.txt
Test003/
Revisions.txt
Test001=2012_12_05.log
Test001=2012_12_06.log
Test001=2012_12_07.log
Test001=2012_12_08.log
... more log files here
You could pipe the output of your command through grep, looking for lines that end with /.
smbclient ... | egrep '/$'
Instead, you could mount the remote windows file system and then use the find command to search for folders. The find command will search recursively for all directories only. This would be my recommended approach. Assuming you mount the windows filesystem as /mnt/win_host...
find /mnt/win_host -type d

Resources