Basic commands in terminal computing
In here, we want to demonstrate basic commands when doing work in the powershell/terminal as well as in the jupyter notebook.
NOTE, that when running terminal commands in the jupyter notebook, you need to add a !
in front of the command, so e.g. !ls
.
File and Directory Management
ls
- shows the content of your current directory.
ls
ls -l # Detailed list (long format)
ls -a # Show hidden files
cd
- Change directory.
cd /path/to/directory
cd ~ # Go to home directory
cd .. # Go up one directory level
pwd
- Print working directory (shows your current directory).
pwd
mkdir
- Create a new directory.
mkdir new_directory
rmdir
- Remove an empty directory.
rmdir directory_name
cp
- Copy files or directories.
cp source_file destination_file
cp -r source_directory destination_directory # Recursive copy (for directories)
mv
- Move or rename files or directories.
mv old_name new_name
mv file /new/location
rm
- Remove files or directories.
rm file_name
rm -r directory_name # Recursive remove (for directories)
rm -f file_name # Force removal (use with caution)
File Viewing and Editing
cat
- Display the contents of a file.
cat file_name
less
- View file contents one page at a time.
less file_name
touch`
- Create an empty file or update the timestamp of an existing file.
touch file_name
tail
- Showes the last lines of a file
tail file_name
tail -n N file_name #shows the last N lines of the file
Search and Find
grep
- Search inside files.
grep "search_term" file_name
grep -r "search_term" directory # Recursive search
find
- Search for files and directories.
find /path -name "file_name"
Compression and Archiving
tar
- Archive or extract files.
tar -cvf archive_name.tar directory_name # Create a tar archive
tar -xvf archive_name.tar # Extract a tar archive
tar -czvf archive_name.tar.gz directory_name # Create a gzip-compressed tar archive
tar -xzvf archive_name.tar.gz # Extract a gzip-compressed tar archive